Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I select an angle to fire a projectile?

alt text

Okay so basically, a game is being created in C++ in unreal. The game is 2D and the character should be able to fire projectiles. Basically, i'm fairly new to unreal and require a push in the right direction to getting this implemented.

I want to be able to do two different things:

  1. How would I limit the the mouse cursor to only be allowed on the red line, such that if you move the mouse upwards it will go to one end of the red line, or down and it will go down another?

  2. How would I calculate the angle between the character and the mouse position, to calculate the angle to fire the projectile off in?

I'm not asking for a full solution, i'm just wanting a push in the right direction?

Any help would be greatly appreciated! (Sorry about the bad paint drawing, haha)

Product Version: UE 4.17
unreal.png (8.5 kB)
more ▼

asked Feb 23 '18 at 07:22 PM in C++ Programming

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi @ibaconbuttys ,

  1. I'm not entirely sure how one can limit the mouse movement entirely what you can do is actually track the direction of the mouse movement using its position you can get this by using PlayerController->GetMousePositon(X,Y). You could then use it figure out direction you mouse is moving. by using the last know position Once the direction is know you could move the retiicle up or down by using the formula X=Cos(Angle)*radius,Y = Sin(Angle) * radius.

  2. You would always have a set Angle before hand. What you'd actually need is the is the direction which the cone/the character is facing/ wants to face.

more ▼

answered Feb 24 '18 at 12:32 PM

avatar image

6 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You can also use vectors in 2D. Then the angle is:

acos( dot( PawnViewDirection / |PawnViewDirection|, ProjectileDirection / |ProjectileDirection| )).

Use this angle to limit the movement in your PlayerController class.

more ▼

answered Feb 26 '18 at 10:44 AM

avatar image

j.mueller RFG
304 3 10 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question