Rockets, show impact on ground

Hey guys <3,

I’m trying to spawn some rockets from the air and I’m trying to make a decal on the ground to see where the rocket will land. Sadly I get a slight position offset and I’m not sure if it’s just because of the physical thruster or if I’m missing something else, pls hahlp <3

Hello @Ninjin,

Could you post a picture of your script in the editor? The color coding of the editor sometimes helps me to understand how the code works.

Farshooter

So, am I correct that the physics thruster shouldn’t be used for this, because it’s just too inaccurate?

So before I can answer whether the physics thruster is too inaccurate, I have to ask you a question in order for me to better understand your what you are trying to accomplish.

Are you trying to spawn a rocket and then immediately predict where it will land?

As you can see in the blueprint, I randomize 2 points. The location of the rocket spawn above the player and the location of the impact. Then I use the function “Find look at rotation” to get the rotation value of the spawn point to the impact point. The Spawn Actor has the rocket blueprint and it has a physical thruster attached to it, right when it’s initialized.

Hello @Ninjin,

Thank you for the explanation in the comments. It really helped me understand what is going on in your code.

So I think I now understand why your rocket is always landing offset of the spawn decal. This is because the moment you add the rocket to the scene, its movement is being controlled by the physics engine. Every physics object that is affected by gravity will travel in a parabolic arc and not a straight line. This explains why your rocket isn’t landing on target, because your target assumes that the rocket will travel in a straight line.

There is a real quick and easy solution to this problem. Just turn off the “Enable Gravity” field in Physics category of the Details panel for the physics object that is being propelled by the rocket. Then the rocket should always travel in a straight line.

52138-enablegravity+1.png

An alternative would be to predict where the rocket will fall based on the fundamental kinematic equations of physics, but this would be difficult, because the rocket will most likely always be accelerating and therefore the decal would have to be constantly updated.

I hope this answer helps,

Farshooter

Gravity was also the first thing that came into my mind, but it’s not the problem here.

Hello @Ninjin,

Important Side Note: This solution assumes that the reader has seen my previous answer about turning off “Enable Gravity” on your physics bodies being propelled by the rockets. This solution will not work if your physics bodies have “Enable Gravity” checked.

I figured out why your rockets weren’t landing where they were supposed to.

Problem:
So to understand why your previous solution wasn’t working, you have to understand how Blueprint function calls work. Whenever a Blueprint function is called by a white wire all its input wires work backwards. So if you have a function that takes in a random number as an input, that random number is calculated every time the function is called. This means that the same input wire will can return different results to different functions because it is computing a new value every time it is called. To illustrate this, I created a some simple test code. I highly recommend you run it and see its results.

As you will see from your output this code will almost always print different numbers. This is because the “Random Float in Range” function is being calculated every time a new “Print String” function is called. Your previous solution was doing something similar to this, but only on a greater scale which made it harder to detect.

Solution:
To solve this problem, simply store the random value into a local variable. This way the random value is calculated once and stored in a variable to be reused reliably in other parts of the code. This is another small scale example that will print out the same random number.

I applied the same solution to your code. I made sure that I calculated the random value of the impact site once and stored it in a variable for use later. Below is the modified version of your code and will produce accurate impact sites for the rockets. I had to cut the solution up into two photos.

Solution Photo 1:

Solution Photo 2:

This question was incredibly interesting and is a great illustration of how Blueprint functions work regarding their inputs. I hope this answer has been informative and will help you out.

Farshooter

Thank you very much!! <3 I’m gonna bake a huge cookie for you :3. Totally forgot to save the random number I generated and somehow thought it’s fine if I just plug in the output of make vector to everything where it was needed. Also Draw Debug really helps alot to further understanding (e.g. had to lower the z value of impact size, because my character root wasn’t on ground). <3 <3 <3