Monday, March 25, 2024

6 Degrees of aiming. Lets talk about it

Cutting to the chase. In my game I want the character to have the ability to aim forward, Upwards, and mid between those two positions. 

So basically 

0 Degrees, 

45 Degrees

90 Degrees

135 Degrees

180 Degrees. 



I asked my bbuddy DharmaPunk 

youtube.com/@DharmaPunkGames for some assistance, because I for the life of me could NOT figure out hwo to get it to work.


Long story short; I got my results via using Enumerators + the logic that I used for making line traces.

Now at the Time I'm using Blueprints to get this done, but I'll just briefly explain what I did s othaht someone could bring this over to C++ (myself lol)

The first thing I did was set up a basic line trace, going forward from the actor's forward position.




Now for the Aim up, it was also VERY simple. At the time I didnt know this functino existed, BUT LO and behold; 

Get Actor Up Vector...
I simply replaced get the forward Vector With the aforementioned up vector, and it works as I need it to!


Now the Mid aim was a bit "trickier". I referred to Reddit and got a clue to my solution. I needed to rotate my Vector by some degrees. 

So What I did was Rotate my Forward Vector times 45 Degrees on the Pitch (Y). And that solved my issue. Eeyrthing else remained the same!
Magic!



Honestly it was very simple once I "figured it out" . Shout out to my friendly devs help. 

Now the next part. Gettin the Projectiles to follow the direction from the Line trace. 

The first thing was establishing a Trace Start and stop. We're going to use that as the Projectile Direction. 
For this, what you'll need t do; is subtract The Actor Location, from the Out Trace End. This basically draws a direction from your projectile. That lokos like this. 


We have to make sure that stays in a Variable that we will then send into Local Velocity from the spawned Projectile like below. (Make sure to multiply this times a float so the projectile will fly!). 


It's




Go ahead and assign the aiming to the controls to you want, and boom! you're done. Now that I'm typing this, and re reading it. Its much easier to do than I remember. I hope this helps someone! (Myself) in the future!