# How to know the angle of collision?

**URL:** <https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question, UE4-27\
**Created:** [March 28, 2022, 6:03pm UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420 "2022-03-28T18:03:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [March 28, 2022, 6:03pm UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/1 "2022-03-28T18:03:39Z")

</div>

I have a sphere in the world. I want the sphere to move at a constant speed. I want the sphere to change direction when it collides.

The sphere has no mass, no friction, and no gravity.

 ![physics](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/0/0/80033a0afb840194419cfd99a5d383cf87eb9b57.png)

I need to know the angle of collision to change the direction of the sphere.

The following is my code to calculate it.

 ![init](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/8/4d84094170ba9710ef29c49fc7522ec45cfdc246.png)

![tick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/5/9d5a027a9242f83208ead4e1886f6ca6a9724a4c.png)

The following part is incomplete:

 ![newVelocity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/3/ce36f3579fba6d540edb1a5be5976e90727e3975.png)

How can I get the collision angle between the two objects? Or some other easier way to achieve this purpose?

Thank You So Much!!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 28, 2022, 9:18pm UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/2 "2022-03-28T21:18:41Z")

</div>

tl;dr:

> How can I get the collision angle?

use Dot Product → ACOSd. It’d be something along the lines of:

`ACOSd (hit SurfaceNormal DOT NormalisedVelocity) * 2`

This should give you a 0-180 range in degrees.

* * *

Is there a reason why you’re doing all this rather than use actual physics?

* * *

> I have a sphere in the world. I want the sphere to move at a constant speed. I want the sphere to change direction when it collides.

**IF** that’s what’s needed, the above seems overengineered. Since you want to take advantage of physics, rely on physics then. Full energy conservation can be achieved by configuring a physical material, overriding _restitution_ and _friction_. Also, removing mass from a physically simulated body is asking for trouble, imho.

You’d need _no script_ for the above and no special settings apart from removing drag (you’ve done this already) and creating a physical material.

* * *

If you absolutely _must_ override physics (which can manifest as a bunch of odd issues further down the line), consider working with direction, not angle:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/2/372d55d6437f1c83039ab79a79fdb8ffcd52ebc2.png)

Alternatively, you could use mirrored velocity from the frame _before_ the hit and skip Direction \* Magnitude.

Converting to angles often leads to pigeonholing oneself into a corner, especially in 3D. On top of that, relying on generated physical hits will be awkward, as above. You might be better off using a floating movement component and emulate it instead with movement direction. Setting linear velocity per frame seems wasteful and defeats the purpose using physics in the first place.

Not sure what the _real_ end goal is so I might be off my mark here.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 28, 2022, 9:28pm UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/3 "2022-03-28T21:28:46Z")

</div>

> [@Ivan3z](#):
>
> Or some other easier way to achieve this purpose?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/7/e67a303acaea76beb50c41f3dc411c189ac87736.png)

This has no script. Is this what you need?

I’m printing velocity every frame in the middle. If the velocity changed due to a massive framerate drop or inadequate float precision (or UE4 + PhysX shenanigans), you could always clamp the vector to ensure it stays as it should and enforce linear velocity then.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [March 29, 2022, 4:04am UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/4 "2022-03-29T04:04:38Z")

</div>

Hi @Everynone

> [@Everynone](#):
>
> Is there a reason why you’re doing all this rather than use actual physics?

I was thinking if i don’t use mass, friction and gravity i would get constant speed because there is not acceleration. But I didn’t know that this would cause problems in the physics simulation. I’m a noob!!

> [@Everynone](#):
>
> Setting linear velocity per frame seems wasteful and defeats the purpose using physics in the first place.

Ok, i won’t use the event OnTick to do this.

> [@Everynone](#):
>
> Not sure what the _real_ end goal is so I might be off my mark here.

At the moment I am shooting projectiles at the sphere. That’s why I don’t want it to stop moving. But I also don’t want it to increase or decrease its speed. Because if it’s too slow it’s boring, and if it’s too fast then it’s very hard to hit. And another problem is when I shoot at it in the same direction of movement, sometimes it speeds up too much and goes through walls.

> [@Everynone](#):
>
> you could always clamp the vector to ensure it stays as it should and enforce linear velocity then.

Ok, Now i seeing variations in the speed of the sphere. Sometimes it goes faster and sometimes it goes slower. I will try it.

Thank you so much for help!! very appreciate!!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [March 29, 2022, 7:51am UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/5 "2022-03-29T07:51:36Z")

</div>

Also, have a look at this thread, there’s a method with pawn movement and projectile movement:

> [@Simple Ball Trajectory](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/12):
>
> I’m super impressed with the amount of work You put in to your answers. I will Of coarse keep working on the different ball actors each with there own solution Until I can find one that works. My concern Like Richmar1 said is that Physics Might be unreliable for my goal As the players Is hitting the ball around In VR with a racket and it will need to feel right. weirdly enough I cant even make my actor with the movement component move Not sure why . I have copied all your settings. …

And, finally, this:

> [@Trying to make a ball that speeds up after each bounce AND doesn't get stuck between parallel walls.](https://forums.unrealengine.com/t/trying-to-make-a-ball-that-speeds-up-after-each-bounce-and-doesnt-get-stuck-between-parallel-walls/150819/13):
>
> Also, here’s a trick I discovered that one time when rolling the abovementioned coins - Linear Damping can be Negative: After trying several different methods for clamping velocity, I settled for this. Do note that the MapRange is \*unclamped \*here, velocities below 5000 result in \*negative \*damping values - they’re accelerated; velocities above 5000 are slowed down. While this system maintains energy (restitution 0) on its own, you may opt to add / remove so…

This will maintain velocity in an uncanny fashion by applying negative dampening which actually speeds things up.

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [March 29, 2022, 6:08pm UTC](https://forums.unrealengine.com/t/how-to-know-the-angle-of-collision/510420/6 "2022-03-29T18:08:01Z")

</div>

Thank you so much!!
