# Simple Ball Trajectory

**URL:** <https://forums.unrealengine.com/t/simple-ball-trajectory/254423>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [October 6, 2021, 11:57am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423 "2021-10-06T11:57:44Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 6, 2021, 11:57am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/1 "2021-10-06T11:57:44Z")

</div>

Im thinking about making a simple game with a ball / projectile behavior similar to Pong or breakout, where the ball Is constantly moving and being deflected correctly of the walls and paddle surfaces In the opposite direction of its incoming direction Like a bouncing ball.

Whats the best way to approach this ? as I think using physics is not the best approach as I would not want to be using gravity as game will be based in 3d world using polygons and not sprite based

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [October 6, 2021, 12:01pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/2 "2021-10-06T12:01:39Z")

</div>

Depends if you want that 8bit nostalgia feel or not.  
For 8 bit thingy:  
if you hit horizontal surface (going up or down) flip vertical speed  
if you hit some vertical surface (ball going left or right) flip horizontal speed.

That is all.

However do some fun projects with vector math, seems you need it.

PS for clarity:  
surface like this ------------------- : vy=-vy  
surface like thins | vx=-vx  
and every tick (compensate for delta tick): pos\_x=pos+vx posy=posy+vy  
to compensate for delta either vx=vx\*delta or vx=vx/delta (dont remember which one is right, google it).

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 6, 2021, 12:05pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/3 "2021-10-06T12:05:23Z")

</div>

I know how to do some vector math , But as Im at work I wanted to get a head start on research before I get home  
I was wondering if it would be done with a hit surface normal and inverting the Incoming vector/velocity.

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [October 6, 2021, 12:08pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/4 "2021-10-06T12:08:04Z")

</div>

Yup, good you know vectors 😃

Hit surface normal, then normalize it (make sure vector is 1 unit long), then DOT product between normal hit vector and up vector and dot between right and normal hit vector.

Dot product is cosinus between vectors. This way you determine if normal hit vector is from horizontal or vertical surface.

Oh and use “Pure functions” for repeated code pieces here (like dot product , then normalize then compare fi its up/down or left/right). When you code you see duplicated code, its perfect for pure function

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 6, 2021, 12:16pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/5 "2021-10-06T12:16:41Z")

</div>

Huge thanks 🙂 I can start that as soon as Im able

---

<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:** [October 6, 2021, 12:45pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/6 "2021-10-06T12:45:08Z")

</div>

Consider exploring a Floating Pawn Movement component (for collision purposes) and mirroring a vector:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/a/cacc1418217d34c13689a9c3b76bdb635c9e7fac.png)

* * *

Or, if you decide to go down the Physics route, disable gravity, constrain to a plane and counter friction & impact energy loss with a physical material. Great potential for uncanny behaviours but can be fiddly.

* * *

edit: consider this a brick candidate: [How to add a hit count (health points) to individual instances? - #2 by Everynone](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/2) in case you need a breakout thing.

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 6, 2021, 12:48pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/7 "2021-10-06T12:48:14Z")

</div>

Top quality reply 👏 👏 👏  
This means I can get a prototype up and running within minutes now .

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 6, 2021, 10:30pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/8 "2021-10-06T22:30:46Z")

</div>

I have made 2 ball actors one with the movement component like above and one with a projectile component . But I have the same issue on both where the velocity of the ball is not constant and keep slowing down to a stop.  
I tried adding add impulse on each hit but its giving erratic results ☹

---

<div class="post-metadata">

**Author:** ![RichmarIII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RichmarIII](https://forums.unrealengine.com/u/RichmarIII)\
**Post date:** [October 7, 2021, 4:02am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/9 "2021-10-07T04:02:40Z")

</div>

I’ve actually been in production of a very similar game inspired by pong for over a year. I can tell you that after the initial testing I did a while back I too came to the conclusion that using default simulated physics just won’t work. What ended up happening was that the simulation would have various errors during bouncing and it cannot be counted on. Also trying to implement other types of movement while using simulation also became problematic. what I settled on is a manual approach instead of simulating physics I use kinematic physics and manually set the balls velocity and speed every frame (via AddLocalOffset()). I also use the OnHit events to detect the surface normal of the surface that was hit and then calculated a reflection vector that determines the desired output trajectory. hope this helps.

---

<div class="post-metadata">

**Author:** ![RichmarIII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RichmarIII](https://forums.unrealengine.com/u/RichmarIII)\
**Post date:** [October 7, 2021, 4:04am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/10 "2021-10-07T04:04:42Z")

</div>

If needed, I wouldn’t mind providing my blueprint for the detection and reflection algorithm

---

<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:** [October 7, 2021, 7:05am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/11 "2021-10-07T07:05:27Z")

</div>

> [@BaseReality](#):
>
> But I have the same issue on both where the velocity of the ball is not constant and keep slowing down to a stop.

Using a floating movement comp means applying an input vector every frame (called `TraverseDir` there) multiplied by a Speed coefficient. So, technically, nothing can slow you down / speed you up since you override it anyway. Or perhaps this needs adjusting:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/4/743300da2565b693cbf8c5b5e8e6ab5a94b1df76.png)

Velocity values for the above. Needs testing for more than a couple of mins, surely, though. 😉 The result seem OK at a glance but who knows how far you need to take it and what you’ll run into:

From my experience, the biggest gripe with this method is handling inter object collisions as movement comps don’t like other movement comps. It needs a separate calculation on impact.

* * *

When it comes to using physics for this, have a look at this thread: [Trying to make a ball that speeds up after each bounce AND doesn't get stuck between parallel walls. - #5 by Everynone](https://forums.unrealengine.com/t/trying-to-make-a-ball-that-speeds-up-after-each-bounce-and-doesnt-get-stuck-between-parallel-walls/150819/5)

CCD (optional, depending on top vel), position & velocity solvers may need adjusting, a physical material is a must. The thing is that the latter opens up so many gameplay possibilities that it’s hard to ignore what it offers.

* * *

My experiences with using the _projectile_ movement component were OK, too; but leaning towards mixed. I don’t have a thread or example about that.

edit:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/e/9ec2dc235e8cc36e330a206e5d0b8955ab063047.png)

At least the projectiles bounce nicely off one another with this:

* * *

Now, if @RichmarIII adds their method, there’d be a nice set of ideas here. Good luck!

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 7, 2021, 6:36pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/12 "2021-10-07T18:36:25Z")

</div>

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.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/4/745993112439ad0f94aed1f567e15c09df23173e.jpeg)

Update:  
Ah sorry It does Move , Its just I was not hitting it. 🤦‍♂️

But both these solutions seems to behave correclty from my Hit with the racket But they Like to roll down surfaces to much and the projectile Method Is Not Acting strange.

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 7, 2021, 6:39pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/13 "2021-10-07T18:39:43Z")

</div>

Thank for the info, and confirming your findings on the Potential physics issues.  
I sure would like to take a look at that BP if the offers is still there. as This is a new area for me as Im mostly working on AI and VR Physics interactions.  
never tried to do balls before 🙂

---

<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:** [October 7, 2021, 6:58pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/14 "2021-10-07T18:58:52Z")

</div>

> [@BaseReality](#):
>
> Ah sorry It does Move , Its just I was not hitting it.

In case there was any doubt:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/7/87393dd29cf0c6bde47356f41e463914b80353a8.jpeg)

There’s no physics sim or gravity. Pawns ignore each other otherwise they get strangely _sticky_ - not sure why; every time a I look at the movement component, it confuses me and a third of the code is deprecated.

---

<div class="post-metadata">

**Author:** ![RichmarIII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RichmarIII](https://forums.unrealengine.com/u/RichmarIII)\
**Post date:** [October 9, 2021, 1:23am UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/16 "2021-10-09T01:23:02Z")

</div>

![BallPhysicsExample](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/1/71c7d46e3008760a6985d59a8da77db93fb5abf1.jpeg)  
 ![BallPhysicsExampleSettings](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/f/3fe28089a33c13bc1b58424e406afeedf6045e42.jpeg)

That example is a simple BP\_Ball Actor that inherits from AActor, nothing more. It’s not a pawn or anything like that so it doesn’t carry any overhead that pawns or projectiles do. to handle inter-object collision interactions, i simply created a new Collision Profile in projects settings called “Ball”, and set my BP\_Ball to that. You can then specify what sort of actors the ball is allowed to interact with. For my game, balls cannot interact with other balls or power-ups that float around. Hope this helps

---

<div class="post-metadata">

**Author:** ![BaseReality](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/basereality/32/893179_2.png) [@BaseReality](https://forums.unrealengine.com/u/BaseReality)\
**Post date:** [October 10, 2021, 7:57pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/17 "2021-10-10T19:57:20Z")

</div>

Thanks Richmar1 👍 👍 👍

---

<div class="post-metadata">

**Author:** ![RichmarIII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RichmarIII](https://forums.unrealengine.com/u/RichmarIII)\
**Post date:** [October 10, 2021, 9:03pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/18 "2021-10-10T21:03:19Z")

</div>

No problem. Let me know what you finally settle on. I’m interested to know, thanks 😊

---

<div class="post-metadata">

**Author:** ![HE4\_Benitez](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HE4\_Benitez](https://forums.unrealengine.com/u/HE4_Benitez)\
**Post date:** [March 1, 2025, 6:48pm UTC](https://forums.unrealengine.com/t/simple-ball-trajectory/254423/19 "2025-03-01T18:48:42Z")

</div>

I have a problem, I want to represent the trajectory of a baseball with this data that trackm gives me but I have no idea how to start.

“NineP”: {  
“Pfxx”: 10.9529,  
“Pfxz”: -1.5426,  
“X0”: {  
“X”: -0.4224,  
“Y”: 15.24,  
“Z”: 1.72541  
},  
“V0”: {  
“X”: 0.92011,  
“Y”: -35.48997,  
“Z”: -0.57359  
},  
“A0”: {  
“X”: 1.80784,  
“Y”: 6.54468,  
“Z”: -10.06127  
}
