How can i realize RTS like movement in 3D space with adjustable acceleration deceleration and top speed? With Timelines i dont know how to adjust the parameters (acceleration deceleration ,top speed) later on but the pawn stops of course at the right location? Without Timelines i have the problem to bring the pawn to stop at the right location because i can’t calculate the right time to start with the deceleration. s=1/2a*t^2 or for deceleration s=v^2/2a isn’t working accurate for me.
did you check if you turn off default drag?(which will slow your unit down to stop when no force is applied)
that could probably explain why the standard formula doesn’t work.
ahh, sorry on my part, after search it’s called “damping”. if you open your asset, go to component mode/view, select your mesh or things that have physics enabled.
Then in the detail tab, physics section, expand to see more detailed options.
Found it set it to zero but nothing changed anyway since i am working with “Set Actor Location” i am not sure if physic even effects the actor!?
Here is the acceleration issue: 4 seconds to get to a speed of 400 with a acceleration of 100 totaly correct: v =at: | t=v/a | t=400/100=4 secs
but the covered way should be 800?! s=1/2a*t^2
What is the BaseClass of your Pawn? If you use Character, then your Blueprint should have a CharacterMovementComponent. You should be able to tweak everything in there.
MaxSpeed, GroundFriction, Acceleration etc.
And how do i use the movement then in 3D? “Simple Move To” is only for 2D with navi-mesh or am i wrong? In the end i want a Space-Ship Movement like in the RTS “Homeworld”.
Yeah, for a space game CharacterMovement doesn’t really work.
In my opinion, for RTS games you don’t really need accurate acceleration/deceleration and physics driven movement. I would just eyeball it actually. So I would just check the distance to the targetpoint Length(TargetLocation - OwnLocation)
Then if the moving actors reaches a certain distance threshold, apply a velocity decay instead of deceleration.
Using Velocity Decay instead of Deceleration, you never reach zero or start accelerating in the other direction. The Smaller the DecayValue, the longer you need to reach a velocity close to zero.
If you reach your target position, then just zero it out manually. From here you just have to tweak the Decay Value to make it look good.
Voila, you never stand still before the target point and you never overshoot.
The distance error is normal because the float point number you get is never exact(not precise enough to be reliable).
So that includes, time delta, your new velocity and the distance calculated every frame.
my log is something like this at the end roughly matches yours.
LogBlueprintUserMessages: Distance: 796.412842 Elapsed: 3.939464
LogBlueprintUserMessages: Distance: 808.127563 Elapsed: 3.971839
LogBlueprintUserMessages: Distance: 824.139587 Elapsed: 4.007854
There are a few ways to “cheat” this behavior, but have different implication.
If you always have a acceleration, max speed, deceleration curve, you can always cheat to use the area map for v,t curve.
Then calculate the area to get your current position from start point(classic train travel distance math quiz).
But this, while more accurate, might be jittery and not as straight forward.( as you have to consider situation where distance is very short that you never reach max speed. )
Since you are aiming to have RTS, then the end position is always know(and precision isn’t that much of an issue).
What you can do is something like DennyR suggested(I did that with UFO to have make it have a constant distance against floor, so it has a damping effect).
You never know what’s the next delta time is, but if you want to stop smoothly, you can use smoothstep function(go google it) when your are close to your destination.
instead of a linear V(or constant a), your start/break will have smooth in/out effect.
if you ever wanted to use in-egine collision for something, then set location is not your best friend.
better start with “simulate physics” on with gravity off, and then build everything with force as input.
(it will make stop at exact point harder, but to some people it might be more straight forward. ie, for certain mass, if you let go your force with damping on, then they will always stop similar range.)