# Rotate mesh towards Toss velocity

**URL:** <https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, Blueprint, question\
**Created:** [August 6, 2022, 2:24am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411 "2022-08-06T02:24:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 2:24am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/1 "2022-08-06T02:24:42Z")

</div>

Hello, I am having a bit of a problem understanding how to rotate mesh towards toss Velocity. I have a mesh with a socket that points to a target.

 ![Mesh Structure](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/3/3530e39aee9a46426076ea9be62eae0ef8040da6.jpeg)

 ![Start and Target Position](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/a/b/daba8a2b245f9aa4c01bc82a4d21a026ad50a048.jpeg)

I have used SuggestProjectileVelocity to find out the toss velocity which is coming out to be fine as in the image.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/4/4/244a2d5e7419904bf84ec56c6a65b0fb257df850.png)

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**

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/c/1ac3a051f7f9cbc96748cac5976825ac051245b6.png)

I hope I am able to explain my problem. Thank you

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [August 6, 2022, 3:26am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/2 "2022-08-06T03:26:44Z")

</div>

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.

> [@Rotate an towards object velocity direction](https://forums.unrealengine.com/t/rotate-an-towards-object-velocity-direction/470840/2):
>
> The simplest way would probably be to add a projectile movement component to the object. That has a built in function for making the object rotate towards its movement direction. Alternatively, you can do something like this: Add on some rotation interp to smooth it out, but that itself will give you the rotation you want, assuming the actor’s “forward” is along positive X in local space.

Let me know if I’m off base, a clarification might get me sorted!

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 4:39am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/3 "2022-08-06T04:39:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 6, 2022, 4:42am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/4 "2022-08-06T04:42:33Z")

</div>

Hi there,  
If you want both shots to match the target location, you may want to try this node:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/f/04f47ef76f667975d308dd075c4dc88008688297.png)

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

---

<div class="post-metadata">

**Author:** ![SupportiveEntity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SupportiveEntity](https://forums.unrealengine.com/u/SupportiveEntity)\
**Post date:** [August 6, 2022, 4:46am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/5 "2022-08-06T04:46:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 4:51am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/6 "2022-08-06T04:51:30Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 4:54am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/7 "2022-08-06T04:54:47Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 6, 2022, 4:56am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/8 "2022-08-06T04:56:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 5:10am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/9 "2022-08-06T05:10:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 6, 2022, 5:40am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/10 "2022-08-06T05:40:48Z")

</div>

> [@FinalRockstar](#):
>
> “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 ?

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.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 6, 2022, 5:45am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/11 "2022-08-06T05:45:54Z")

</div>

Thank you for taking the time out. I will come up with the update as soon as possible

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 6, 2022, 3:32pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/12 "2022-08-06T15:32:38Z")

</div>

Great.  
Looking forward to seeing if works.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 7, 2022, 8:42am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/13 "2022-08-07T08:42:21Z")

</div>

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

![Overshooting](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/e/65e504774ed5d50eb8230e290eeb0e872b6f7f8b.gif)

#### Blueprint Setup

> **[ShooterActor posted by anonymous | blueprintUE | PasteBin For Unreal Engine](https://blueprintue.com/blueprint/3zg-merw/)**
>
> No description provided

* * *

#### Using Socket As Start Position

![Socket](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/a/5/9a5c951467d0edd547d141994f88cd1012d19b42.gif)

#### Blueprint Setup

> **[Shooter Task With Socket as Start posted by anonymous | blueprintUE |...](https://blueprintue.com/blueprint/niykc3_b/)**
>
> No description provided

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.

 ![Mesh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/6/ab6a119b7ec900c7a2bdfed67be977713cbdc48d.jpeg)

And Shooter Actor is a simple one that just rotates

 ![Setup](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/c/fbc2098ff44ea595355dc1a7fae379e44b47b4cc.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 7, 2022, 12:14pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/14 "2022-08-07T12:14:06Z")

</div>

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”:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/4/9f4292b2e9d1ef0ef0e92fcf89cbd8dac46c602c.jpeg)

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

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/0/5/10544e60f492658a4e0c0a837cfdee0b0afc4594.jpeg "UE5 - Modding Lyra Starter Game: Add Fireball Ability (4k - Timelapse 3x) #LyraUE5") ](https://www.youtube.com/watch?v=JYkLywIgSeU)

Hope that helps.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 7, 2022, 4:25pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/15 "2022-08-07T16:25:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 7, 2022, 4:38pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/16 "2022-08-07T16:38:37Z")

</div>

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.

Keep up the good work.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [August 7, 2022, 4:43pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/17 "2022-08-07T16:43:20Z")

</div>

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [January 20, 2024, 4:34am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/18 "2024-01-20T04:34:03Z")

</div>

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?

```auto
void UMortarProAimingComponent::CalculateAimDirection(FVector& AimDirection)
{
        FVector OutLaunchVelocity = FVector::ZeroVector;
        UGameplayStatics::SuggestProjectileVelocity_CustomArc(GetWorld(), OutLaunchVelocity,
            Gun->GetCenterOfMass(),
            AimDirection);
            
        AimDirection.Z = OutLaunchVelocity.Z;
}

```

Here is the expected gun direction. In other levels it is working fine.

 ![Correct](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/f/9/ff9415f220339f0fdf411d9975db1bce1746ed59.jpeg)

And Here is the actual gun direction in Infinity Elven ruins.

 ![Wrong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/4/0/5405e1f444008bc7421ded43d491d0a595ea700d.jpeg)

And After calculating the AimDirection I adjust the Gun Elevation.  
`Barrel->Elevate(AimDirection);`

```auto
void UMortarProBarrelMeshComponent::Elevate(const FVector &ElevateDirection)
{

	FRotator BarrelDesiredRotation = UKismetMathLibrary::FindLookAtRotation(GetComponentLocation(), ElevateDirection);

	FRotator BarrelDeltaRotation = FMath::RInterpConstantTo(GetComponentRotation(), BarrelDesiredRotation, GetWorld()->DeltaTimeSeconds, 180);

	FRotator BarrelOriginalRotation = GetComponentRotation();

	//Only Require To Update Barrel Pitch
	float ProcessedElevation = FMath::Clamp<float>(BarrelDeltaRotation.Pitch, -30, 70);
	BarrelOriginalRotation.Pitch = ProcessedElevation;

	SetWorldRotation(BarrelOriginalRotation);
}

```

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [January 20, 2024, 6:10am UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/19 "2024-01-20T06:10:42Z")

</div>

Hi there,

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.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [January 20, 2024, 2:34pm UTC](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411/20 "2024-01-20T14:34:19Z")

</div>

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.

[Next page](https://forums.unrealengine.com/t/rotate-mesh-towards-toss-velocity/622411.md?page=2)
