Now the problem is at what angle should I rotate as the toss velocity is coming from the socket location but I want to turn my mesh whose pivot point would be different from the socket location. Like what would be theta1
Hey @FinalRockstar, so if I’m understanding the problem correctly, you’re pathing the arc from the projectile socket but want to rotate the gun itself and not a projectile of it, and you just want the gun itself to rotate towards it’s current velocity?
I myself have only ever used the projectile component since it has this functionality built in, however there’s more custom approaches to this. I came across a thread that does just a basic turn object to it’s velocity but I feel like I’m missing something with the casting from the projectile shooting socket.
Let me know if I’m off base, a clarification might get me sorted!
Hi Yes you understood the problem correctly . I want to rotate my mesh towards the toss velocity. But I have a question . I have calculated Toss velocity from socket so if I normalize and find the direction from socket then the direction which is pointing at, will it be same for mesh also ? So I just need to use find look at Rotation function where start would be mesh location and target would be the normalized toss velocity? Or do I need to apply some more calculations? I will also try with projectile component if I am unable to solve. Thanks for the info
Start Pos will be different for each actor, but End Pos will be the same.
Then, you can use find look at rotation to rotate your mesh towards the target position with Set Actor Rotation
If you are working from that socket specifically I think you’d have to do an arc from the gun’s pivot/center of mass and use that instead as unless you’re prepping the arc for the projectiles themselves instead. You could do this from a different socket, the sm itself, or you’d have to overlay some more math over the arc from the projectile socket, but that’d be more complex than just doing the arc with the gun itself
Hi thank you for reply so I want to ask what is the difference between both these functions other than custom arc has fixed arc of 45 degree. Also I have only one actor to shoot which is having a socket (not multiple actors) . I am using suggest velocity from socket and if I use the result from that and rotate actor from center of mass then won’t it be wrong ?
If I use suggest velocity from center of mass of mesh then won’t the projectile overshoot the target? And if the center of mass is way back then the result could be very far ?
You can use the socket location instead. The start pos is the actual spawning point. Then use the suggested velocity to set your projectile initial velocity right after spawn actor (projectile) from class.
Arc Param = 0.5 is about 45Âş degrees
I guess you should calculate the find look at rotation for aligning the canon angle, then calculate spawn velocity with the suggested node. From what I could see, the canon is only a component of the tank, correct? In this case, you can use control rig or “skeleton control” transform modify bone to rotate in world space.
Yes so I will use the socket location to find toss velocity and will set the initial velocity of projectile to the suggested velocity that part is clear, I am more concerned with the alignment of cannon at a correct angle.
“I guess you should calculate the find look at Rotation for aligning the cannon angle” - so the target would be the toss velocity from suggest velocity function which used socket’s location as start position? Will that be correct ? I will need to check it.
Yes it’s a part of component of a tank but it doesn’t have any skeleton.
Yes, you can you the node “find look at rotation” to set the cannon rotation in world space. If the canon is a child actor of the tank, it will be easier to get its actor rotation. The start pos for the cannon should be the canon’s pivot point. The end pos is the target. Also, the start pos for the shot is the socket location, and the Pitch Y Axis angle should be 45º. So, the only angle missing is the Yaw ZAxis taken from find look at rotation.
First you align the cannon to the target, then calculate the shot velocity and spawn the projectile from the socket location. The projectile velocity is set by the suggested velocity after spawn actor from class.
I hope that makes sense. I’ll check up on you tomorrow.
Hello, So I have tried to use Socket as well as Mesh as the start Position. Here is my observation
Using Mesh As Start Position
Blueprint Setup
Using Socket As Start Position
Blueprint Setup
I have changed My mesh to be a very long box. I did this to figure out any issues easily as with the Gun it was shooting target correctly because the difference between socket position and gun center of mass position was not enough.
As you can see in both the setup the shooter actor is able to turn correctly but the problem is for Pitch as in one it overshoots and in the other it undershoots.
Hi there,
Thank you for sharing the logic, that helps to understand what is causing the issue.
You’re almost there. I believe you’ve missed that “find look at rotation”:
If you’re changing the cannon’s pitch, this information should be feeding into the projectile calculation, however only the node “Suggest Projectile Velocity with Custom Arc” has such parameter exposed in Blueprint. Keep in mind that the cannon’s pitch of 0 - 90º equals to 1 - 0 in that node (“Arc Param”). So, you’ll need a “map range clamped” node.
In my timelapse video, I show how to use that node with a projectile launch at time 1:03
Thank you for taking out time to answer. If I use ActorToPoint’s Location in FindLookAtRotation then the Shooter Actor or Cannon will directly point to Target instead of slight inclination. Although by setting velocity the projectile hits the right target. This inclination problem may or may not be noticeable. As of now, I am happy with the solution you provided : )
As for “Suggest Projectile Velocity with Custom Arc” what is the difference between Out Launch Velocity and Toss Velocity of “Suggest Projectile Velocity"? I am sorry for asking too many questions.
Hi there,
Glad it helped you. The velocities are the same, the different is that you have more inputs to control your trajectory with Suggest Project Velocity with Custom Arc. Also, I believe Out Launch Velocity is a direct reference to the input used in the node Lauch Character.
Hi apologies for coming again on this topic but I am facing some issue with Suggest Project Velocity with Custom Arc for the same project.The issue is
in Infinity Elven Ruins Level the Gun is Aiming wrongly. i.e it is aiming downwards. But in all other levels the gun is aiming correctly i.e in an arc. I don’t know whether it is level specific issue or issue with the code. Here in the Function AimDirection is the target position. I am trying to rotate my Gun in a direction so that it can hit a target while aiming in an arc. Is it a right way of doing?
Can you please record a short video showing the issue in the Elven Ruins? Are any of the actors below zero altitude? It might be a calculation error that is causing the cannon to look downwards, for instance, if the end position is below the tank, and you’re using find look at rotation, perhaps you want to constraint the values of pitch so the cannon will never look down. Please record some videos or screenshots and I get back to you tomorrow morning.
The red sphere denotes the position of the target, and the green sphere is the direction in which the gun should aim to hit the target. I discovered this is not specific to Elven Ruins, as in the map, the ground level is at around 7000 Z units. If I keep the gun near the origin, then it works fine, but if I keep the gun way above the ground, then it points downward. I feel there is some calculation mistake going on.