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?
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.
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?
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.
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.
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?
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.
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):
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):
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.
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?)
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:
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:
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:
…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:
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.