# Simulating gravity when moving up or down an incline

**URL:** <https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 11, 2021, 8:14am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378 "2021-11-11T08:14:09Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![RavagingRunt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RavagingRunt](https://forums.unrealengine.com/u/RavagingRunt)\
**Post date:** [November 11, 2021, 8:14am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/1 "2021-11-11T08:14:09Z")

</div>

Is there a way to simulate gravity so that when a ball moves up or down a ramp, it decelerates or accelerates? My pawn is a ball that rolls across a course and it is propelled by an ‘on tick’ event that adds movement input.

Do I need to somehow detect the slope of the surface that I’m on and change the movement scale based on whether it’s a slope? Or is there some easier way to do this?

Thanks for taking the time to read this!

-Dan

---

<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:** [November 11, 2021, 8:17am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/2 "2021-11-11T08:17:22Z")

</div>

Is there a reason you do not use physics for your pawn (ball)?

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [November 11, 2021, 11:39am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/3 "2021-11-11T11:39:27Z")

</div>

Because it’s a pawn. You can’t “simulate” on it that easily.  
Also add inpulse or add movement input are constant, so you do need to scale them down based on the slope.

Assuming the pawn already does a line trace, read the slope from the impact normal.  
You can get the approximate ratio by just doing dot of the impact normal vs the pawn up vector.

Result will be in the -1 to 1 range.  
You may be better of with a dot against the forward vector so you know if you are heading up or down the slope with the positive / negative.

With the result of the dot, and the previous frame speed, you can apply some baseline physics math to increasingly reduce the speed.

Or you can simply reduce the axis value by multiplying by .99 and updating it over and over while the dot result is positive.

Applying physics math will feel a lot better gameplay wise.

---

<div class="post-metadata">

**Author:** ![RavagingRunt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RavagingRunt](https://forums.unrealengine.com/u/RavagingRunt)\
**Post date:** [November 11, 2021, 11:59am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/4 "2021-11-11T11:59:33Z")

</div>

Thanks for answering - is there a check-box for that somewhere in the Blueprint? I’m not seeing it ☹

---

<div class="post-metadata">

**Author:** ![RavagingRunt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RavagingRunt](https://forums.unrealengine.com/u/RavagingRunt)\
**Post date:** [November 11, 2021, 12:02pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/5 "2021-11-11T12:02:09Z")

</div>

MostHost\_LA - Thanks for the quick reply. It makes sense that I’d need to scale the impulse based on the slope - I don’t quite understand how I’d read the slope from the impact normal - is there a collision that I can detect and get the “Impact Normal” and “Pawn Up” numbers so I can do the appropriate math?

---

<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:** [November 11, 2021, 1:26pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/6 "2021-11-11T13:26:04Z")

</div>

I was wondering why you cannot simulate physics on pawn, because i did it some time ago.  
I made physics based space ship, and moved it around with physics thrusters.  
It was not that hard.

For gravity you can add thruster right on top of ball adding thrust down. This should work for pawn.  
Using impulse depends on frame rate so may have weird results.

---

<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:** [November 11, 2021, 2:20pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/7 "2021-11-11T14:20:22Z")

</div>

> [@RavagingRunt](#):
>
> is there a check-box for that somewhere in the Blueprint?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/f/1f6ac1401e295d79c9edd8717a3bfe4597044c59.jpeg)

Physics sim is the way to go. You can add a Floating Pawn Movement Component for extra fidelity / control:

This will also give you the chance to utilise physical materials later on, mainly for control over friction and restitution. They really open up gameplay options.

* * *

Also, consider checking out the rolling ball template - it’s set up with the pawn + physics + torque combo.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [November 11, 2021, 8:29pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/8 "2021-11-11T20:29:27Z")

</div>

I disagree in principle.  
Specifically with chaos being a mess.

And no. Physics isn’t hard. Just very unreliable and getting even worse with what’s coming.

> [@RavagingRunt](#):
>
> I don’t quite understand how I’d read the slope from the impact normal - is there a collision that I can detect and get the “Impact Normal” and “Pawn Up”

In blueprint pawn up vector you can pull out of a “self” pin. Or forward vector.

For the collision you just set up a line trace. Very basic.  
Just like the character movement component.  
Same idea.

---

<div class="post-metadata">

**Author:** ![usa423](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/usa423/32/918773_2.png) [@usa423](https://forums.unrealengine.com/u/usa423)\
**Post date:** [November 12, 2021, 3:42am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/9 "2021-11-12T03:42:02Z")

</div>

That is interesting. I never knew about that “Add torque in Degrees” node. What would be the closest node to that for just straight vector propulsion? Add world offset?

---

<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:** [November 12, 2021, 9:27am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/10 "2021-11-12T09:27:42Z")

</div>

> just straight vector propulsion

Torque is for adding angular momentum - rotating. Add Force / Impulse is linear - direction. There’s a difference between the 2 nodes:

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

Add Impulse is generally used as a singular event if you want to transfer that much force in one go. Kick a ball, a projectile connects with target, start a ragdoll.

**_Add Force_ would be the propulsion thruster.**

* * *

There is also this component:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/9/79c86077bf6921d8a7374010c8d9f81b77274836.jpeg)

Which can simplify things if you need several points at which forces are applied; also comes in node flavour:

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

* * *

On top of that, you can _override_ physics with Set Linear Velocity / Angular nodes. This will disregard what the physics is currently doing and produce a new traverse velocity / angular (but they can be made additive, too):

![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/8/48b011a1003ceff8faf2825812547dab9cbafbf7.png)

The above examples work with physics.

* * *

Add World Offset, on the other hand, moves an actor from A → B instantaneously using a delta and has nothing to do with physics. But you can apply a small Add World Offset value every frame. And its Sweep can be used to detect collision (not without limitations, though; it’s by no means perfect out of the box):

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

Still, no physics here.

---

<div class="post-metadata">

**Author:** ![usa423](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/usa423/32/918773_2.png) [@usa423](https://forums.unrealengine.com/u/usa423)\
**Post date:** [November 12, 2021, 6:38pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/11 "2021-11-12T18:38:00Z")

</div>

Thanks for the very thorough and detailed explanation with pictures.

“Add Impulse is generally used as a singular event if you want to transfer that much force in one go. Kick a ball, a projectile connects with target, start a ragdoll.”

Would that then be the best choice for like a tank blast? Like the body of the tank being kicked back by the force of the turret firing?

I take it then add force would be more solid thrust then and not a one off or kick as you put it. I have tried to use physics thrusters with various results. How would you describe the difference between Add force and PhysicsThruster?

Add Force at Location - Could you describe that better to me? Thanks.

" On top of that, you can _override_ physics with Set Linear Velocity / Angular nodes. This will disregard what the physics is currently doing and produce a new traverse velocity / angular (but they can be made additive, too):"

That sounds interesting to me, in particular the Set Physics Linear Velocity node. Will this node work standalone or does it need another node to function? So then once its target is connected to a physics enabled mesh, I could simply type in say 100 Z either plus or minus and receive a push or pull of 100 units in the Z on the static mesh? If its like physicsthruster I imagine I will need ridiculous numbers in order to have solid night and day effects.

Set Physics Angular Velocity in Degrees - Maybe that is actually the node I’m thinking of when I say propulsion.

“Add World Offset, on the other hand, moves an actor from A → B instantaneously using a delta and has nothing to do with physics. But you can apply a small Add World Offset value every frame. And its Sweep can be used to detect collision (not without limitations, though; it’s by no means perfect out of the box):”

But that is just the thing, no physics, I have seen a lot of tutorials that seem to use Delta as the main mechanism of propulsion for flying craft.

Again, thanks for your time.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [November 12, 2021, 10:13pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/12 "2021-11-12T22:13:10Z")

</div>

Because 10 times out of 10 an aircraft does not need to simulate physics.

Realistically the engine’s implementation of physx isn’t even remotely close to being refined enough to allow for the physics involved in generating a flying object - let alone a helo or a plane…  
Essentially you always fake things by disabling gravity and approximating movement.  
And you end up doing stall mechanisms based on 1st grade calculations on engine speed vs vehicle height.

Also 9 times out of 10 the physics of the engine will fail unless you enable sub stepping for it.  
Because calcs are otherwise tied to the FPS.

Best example to be aware of.

You have a collision box of 1cm.  
And a wall to collide against that’s 10cm tick.

If the box is traveling at 100cm x frame.

What are the chances of the box colliding with the wall? (And what do they rely on?)

---

<div class="post-metadata">

**Author:** ![RavagingRunt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RavagingRunt](https://forums.unrealengine.com/u/RavagingRunt)\
**Post date:** [November 13, 2021, 8:06am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/13 "2021-11-13T08:06:55Z")

</div>

Thanks, I got great results with adding torque. I really appreciate the assist!

---

<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:** [November 13, 2021, 2:54pm UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/14 "2021-11-13T14:54:45Z")

</div>

> [@usa423](#):
>
> Would that then be the best choice for like a tank blast? Like the body of the tank being kicked back by the force of the turret firing?

Sure, why not. Add Impulse:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/7/07b6e40ecdc8dc4ee00db6f9a7eb0528a5896c3d.png)

Perfect if only the suspension wasn’t a slab of concrete… 😉

* * *

> How would you describe the difference between Add force and PhysicsThruster?

Add Force at Location vs Thruster Component. One is a node and the other a component. Apart from that, there’s no difference under the hood; there’s hardly anything on the C++ level in the comp. It’s just a ticking component with a single var. Use it as a base class and flesh it out, so it actually does something interesting - it being a component makes it easy to attach to things and move around / point at things. You can do it in BPs, too:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/3/5370f55e61d2c0fd2018e4db91a25cfaf49cc05d.jpeg)

* * *

> Add Force / Impulse at Location - Could you describe that better to me?

If you’re not using location, you’re applying the force / impulse at the root (UE4’s physics implementation supports component welding - so there’s more to it, actually). Doing it _at location_ instead, allows you to do this:

You choose _where_ the force / impulse is applied. If you wanted to tip a big box over, you’d push the top edge. If a flying drone has 6 engines, to make it fly correctly, you’d apply forces where the engines are located to give it stability.

* * *

> Set Physics Linear Velocity node. Will this node work standalone or does it need another node to function? So then once its target is connected to a physics enabled mesh, I could simply type in say 100 Z either plus or minus and receive a push or pull of 100 units in the Z on the static mesh?

It’s just a single node. It literally overrides the physics state. Whatever you were doing before, now you’re doing this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/9/19dc8f209bb8aa0a6f62b741a1152993be407fb1.png)

This is quite different from Adding force / impulse as it disregards the previous state. If your supersoldier had the ability to deflect bullets back at the enemies, you could use this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/3/d3834b9c5e325ca742ff6948fa9d4d77d81a5e9a.png)

…and even dare to ignore the friendly warning it comes with.

* * *

> But that is just the thing, no physics, I have seen a lot of tutorials that seem to use Delta as the main mechanism of propulsion for flying craft.

You sure can, but that’s not physically accurate, and not a simulation. That’s unless you write enough code (a lot) to essentially achieve a custom physics engine…

There are lot of forces affecting a plane in flight. A single thruster would produce the same effect as attaching a fan to a piece of cardboard. It would fly, just not very well.

Have a look at the threads below, they really go into details - these 2 are literal gold mines:

> [@\[OPEN-SOURCE\] Machinery Modelling Toolkit](https://forums.unrealengine.com/t/open-source-machinery-modelling-toolkit/54422):
>
> \*\*No C++ is needed, this works as Rama’s Victory plugin - it adds extra nodes and classed to BP. There is no need to write C++ code unless you really want to smiley \*\* Feature plans The long term plan is to extend plugin with more functions which a necessary for physics calculations and add more components that can be used as building blocks to model whatever you want. Components such as wheels, tracks, springs, suspension, airfoil, engine, gear box and many more. Small bui…

> [@\[ASSETS\] \[OPEN SOURCE\] Tanks, tracks and N-wheeled vehicles](https://forums.unrealengine.com/t/assets-open-source-tanks-tracks-and-n-wheeled-vehicles/41018):
>
> Hi guys, I was working on a prototype of off-road tracked vehicle similar to this amphibious beast of engineering: [[- YouTube] ](https://www.youtube.com/watch?v=ky16Ac7Q7yU) It was obvious that I should look into PhysX’s tank implementation but I’ve decided that first I want to get my own implementation in blueprints, to better understand what kind of forces are involved in simulation and how far you have to go in respect to reference materials. Prototype started with a huge vehicle, supported by 10 wheels of 2 meter diamete…

---

<div class="post-metadata">

**Author:** ![usa423](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/usa423/32/918773_2.png) [@usa423](https://forums.unrealengine.com/u/usa423)\
**Post date:** [November 14, 2021, 3:48am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/15 "2021-11-14T03:48:31Z")

</div>

Ok thanks for the reply, I will try to remember that stall mechanism you just proposed.

---

<div class="post-metadata">

**Author:** ![usa423](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/usa423/32/918773_2.png) [@usa423](https://forums.unrealengine.com/u/usa423)\
**Post date:** [November 14, 2021, 4:07am UTC](https://forums.unrealengine.com/t/simulating-gravity-when-moving-up-or-down-an-incline/260378/16 "2021-11-14T04:07:29Z")

</div>

Many thanks Everynone for making this awesome response with all these examples.

- that first example pic, I’m assuming that the negate vector node takes the vector and gives back the exact opposite?

“Perfect if only the suspension wasn’t a slab of concrete…”  
hehe

“Add Force at Location vs Thruster Component” “there’s no difference under the hood”

Like many things in UE4 then, many things can ultimately accomplish the same task.

“If a flying drone has 6 engines, to make it fly correctly, you’d apply forces where the engines are located to give it stability.”

About that…I kinda wish Epic would create like a nozzle control for the physics thruster…I mean where you adjust the output of the thruster to narrow or wide. I would think for aircraft it would be better to have a wide output so it would all be smoother. Perhaps then at this point the answer is quantity (6 engine drone) vs quality with the current physics thruster. Now that I think of it, that would make for an interesting variable to control, adjusting this lensing or focusing effect at run time, to focus the output to a narrow laser or pencil but then a wide force that is lower pressure but greater area. They probably should attach some smoke particles to this out of the box, so one could have a wind tunnel effect and see these effects real time. Thanks for all the links.
