I have a BP actor that spawns high in the sky and is supposed to fall down to the ground (I’ve enabled physics and gravity). At a certain distance from the ground, I’d like this actor to slow down as it gets closer to the ground and effectively “land”. Think like maybe a space x rocket or something.
Any idea how I can do this?
Hey @JontheBaptist how are you?
Ok, I’ve been trying to do something like this using blueprints and I found that the best way is to disable physics and gravity, and create a custom system for it!
Let me explain the process step by step:
-
Disable physics on your actor’s mesh on your Begin Play:
-
You will need to create some variables for your actor:
-
Assign default values to those variables:
Fall Velocity: 0.0
MaxFallSpeed: 2000.0
CurrentDistance: 0.0
IsFalling: true
Power: 3.0
StartLandingAltitude: 600
FinishLandingAltitude: 100
LandingLocation: 0.0 , 0.0 , 0.0
-
In your Begin Play, set the Fall Velocity equal to negative Max Speed:
-
Now, on your Event Tick, create a branch with IsFalling as its condition:
-
You will need to create a new function, I called it “ReduceSpeed”, and it will check the altitude and move the actor towards the ground at the corresponding speed based on altitude. Let me explain it here:
a) First of all, you need to add a float input called Delta Time to your first node, then check your actor’s current location and make a Line Trace towards the ground:
b) After that, you will break the hit result, store the distance in your Current Distance Variable and check if it is less than your StartLandingAltitude variable:
c) From the true pin of the branch, you will calculate the FallVelocity:
d) After seting the FallVelocity, you need to check if the CurrentDistance is less than FinishLandingAltitude, and if it is true, store the landing location you got from the “break hit result” on the “b” step in your LandingLocation variable and set the IsLanding variable to false:
e) Immediately after that, you will need to put a “set actor location” node, and connect it to both branches’ flase pin, and to the “IsFallin” exec pin as well:
f) Now you need to calculate the new location for that last node and connect the result to it, you can do it this way:
-
Now that we have the function completed, is time to call it on the event graph. It needs to be called in the true pin of the event tick branch and connect the Delta Seconds from the Event Tick node to the Delta Time of your function:
-
The last step is to create a timeline for the last part of the landing and connect it to the false pin of the event tick branch:
This is the timeline track:
First Key: Time 0.0, Value 0.0
Second Key: Time 0.1, Value 1.0
With “Auto” interpolation enabled.
And that’s it! Of course you can play with the values of “MaxFallSpeed”, “Power”, “StartLandingAltitude”, and “FinishLandingAltitude” variables to polish the effect! But this is a decent starting point haha
It will look like this:
Hope this works for you!! Let me know if you need more help with this!