Visualizing a Trajectory

I know there is functionality to show predicted trajectories in UE4, whether with C++ or blueprint. It’s been before for things like Gears of War’s Grenades and Torque Bow Weapons, I want to do a similar thing for my game.

What’s the most basic way to draw a trajectory, I guess at first I would use a DebugLine, and then switch to a particle system using a beam at a later date. Has anybody this yet? I want to basically be able to give the game a set of data like Velocity, Gravity etc and it’ll show me a reliable trajectory. It’s actually for a space-based game.

To get positions on the projectile path, and the shape just Google “projectile motion”. The equation is:
X = StartX + Velocity.X * Time
Y = StartY + Velocity.Y * Time
Z = StartZ + Velocity.Z * Time + (Gravity * (Time^2))/2
And to draw it use a particle system.

1 Like

Debug lines and lines from line traces suffer from one problem. They don’t scale with distance. So they give a wrong impression.

I suggest you make a mesh with a transparent material and stretch that for each part of the trajectory. I think that will give you the best visuals.

I have made a small demo of bulletdrop and travel time, it doesn’t predict trajectory, but that’s just a small change to do that instead. It uses the line from a line trace… and it is the same width the entire length of the trajectory.

If you want a curved trajectory (I’m assuming you do, since a straight line isn’t tricky), you could always use a segmented narrow plane with a ‘bent’ blendshape on it - and then control the amount of that bend based on your trajectory math?

Coming back to this as it’s still a problem. What I’m trying to do is create a ribbon trail, IDENTICAL almost to Gears-Of-War’s Aim-Trail system. It HAS to be instantaneous, and it has to be every frame. We’re trying to do what Kerbal Space Program does, and predict the orbital path of objects orbiting around each other (using PhysX forces).

We have our calculation for gravity, what we now need to do is simulate this many times every frame for a dummy ‘tracer’ object, and leave behind a trail. I’ve seen a few examples, but most operate on the same time-frame as the object you’re trying to predict and are therefore no use to us. We need instant feedback on where you’re ‘ship’ (or whatever object) will be, and it has to be accurate.

Feel free to throw C++ at me, or if Epic could shed some light on how they did Gears’ aim trails that would be great. I can get Gears of War UScript source files, but it’s a nightmare to pull apart and I never did any UScript, so I figure I’d have a hard time making sense of it.

This is something I plan to work with myself, and that I’ve already something small with in Unity before I came here.

In Unreal my first attempt is likely to be:

  • Create an object in world of the type I would like to simulate
  • Set a flag to:
    • Disable Rendering and sound
    • Disables anything that affects the world around it, such as any damage it might deal
    • Set collisions such that the object will bounce but won’t interfere with “real” objects.
    • Create a trail visualizer and add a point each tick.
  • Set the time dilation value such that the actor would be ticked FAR more often than normal
  • Treat the object as you would a real version.

I can’t promise this will work as you need, but it’s what I plan to try myself. If that doesn’t work I’d do what I did in Unity and run the object’s tick multiple times per frame.

Yeah we tried this using Time Dilation, but for some reason the Time Dilation doesn’t seem to have any effect on PhysX objects or actors.

What we really should do is write our own movement code, and then simulate it really quickly to leave behind a trail of points. I just wish I knew how Gears did it… they managed to do exactly what we’re looking for with their Grenade and Torque-Bow aim trails. Even Rama has tried it before in UDK but to little avail (still requires time to make the trail, ours needs to be instant)

I don’t know if “exact” would be really necessary, most games, if any, are not accurate if there is any collision/bounce off wall prediction.
Sometimes it’s just there to show you that if you throw it’s gonna hit the window, and the trajectory are just roughly right.
ie. games like Uncharted, Wolfenstien, etc. I am not familiar with Gears with later series, but aiming with trajectory is kinda pain in the butt. especially when you want to have a bounced grenade to land where you want.

Most of the time, the first hit location will be proper for AAA game, but for bounce hit location, not much.

There is no way to do what you want short of ******** with PhysX itself.

You will need to recreate the effects of the PhysX objects you want to work with. That is, derive when and how the force volumes affect acceleration (velocity and position), and account for it in a special object (your dummy tracer) that essentially runs its own version of the physics engine in a for loop.

Luckily, the kinematic equations are pretty simple, so this isn’t a particularly daunting task; as long as you understand exactly how your force objects will affect your affected object and there are bouncing no collisions, you should be safe.

It is for us because we’re building a product to client specifications, and accuracy is a key part of the final project. Also, please note I’m not calculating projectiles or bounces/collision, I’m predicting paths for objects as if they are in orbit. Collisions don’t even have to register at all.

Something similar to Kerbal Space Programs’ predicted orbital paths would be sufficient. Unfortunately they haven’t revealed how they did it. What we want to do is run the current simulation very many times, create a series of points and create a spline between them, doing this many times every frame. Later we can optimize it so it only runs that simulation if the orbit changes.

This, is what we need.
95d286953332bee5fc0f8ca089785d14ec831b22.jpeg

basically, what KSP did is taking the liberty of massive difference in mass between your shuttle and the planet itself.
So for most of the case, the orbit you are on, planet are always in one of the 2 focus points of a ellipse.
The tangent speed you applied changes the distance of focus points thus change the result of predicted orbit.
In case of moon landing, it’s more complicated, but I assume similar principle applies.

It really depends on what you want to achieve really, as orbit is kinda special case(where most planet/moon bodies won’t change their existing orbit because of mass difference).
I doubt you can give much detail about what you guys are contracted to do, but not everything has to be simulated to get the results right.
(Of course NASA isn’t going to risk some decade projected launch(like recent probe orbiting a comet) from KSP, it’s a game after all.

Ok a few things on trajectories of celestial bodies. It is nearly impossible to compute systems with serveral bodies influencing each other. Your only option is to simulate the system UNLESS you simplify the problem to a simple two-body- or one-body-problems.

Kerbal Space Program does the latter. It uses spheres of influence (SOI)](Sphere of influence - Kerbal Space Program Wiki) for planets which indicates how far a certain body attracts others. Read: Patched Conic Approximation.

So for example if a spaceship is in earth’s SOI, you only have to calculate spaceship to earth attraction which can be solved using kepler orbit equations given an initial state.. As soon as you leave earth’s SOI, you take the next bigger SOI, which would be the sun. If you fly into moon’s SOI however, you would take moon’s SOI and completely ignore equations with the earth.
The only thing you have to consider, is inheriting velocities. So every object that is orbiting around earth, has to inherit earth’s orbit velocity around the sun. Objects orbiting moon, would have to inherit moon’s velocity around earth (and moon has to inherit earth’s velocity around the sun).
So you have to do a bit of orbit transformation when you enter/leave SOI’s. Also SOI priorities are needed to make it easier to check which is current SOI if you are in serveral SOI’s (example moon and earth).

On top of that, I believe that Kerbal Space Program calculates their orbits using Apsis which allows to store orbit information in 2 points (Apoapsis and Periapsis + Velocities at those points + time at which the object reaches those points). This allows you to pretty much derive every position of this object for every given time.

As far as visualization goes, I would go for splines, since they give you the most reliable outcome.

TL;DR:

  • give every planet a sphere of influence
  • only calculate orbit for objects in the SOI and ingore all other objects
  • objects orbiting other objects have to inherit their velocities to make a working star system
  • Calculate trajectory using kepler’s planetary motion equations.

That said, I played the **** out of KSP and loved it :stuck_out_tongue: I actually went to implement my star system because of KSP. But I didn’t bother with drawing predicted trajectories, because I knew it would take quite a bit of time and work to get this right, but I guess I have the theory down nonetheless.

1 Like

Thanks for the help, adding some more points to this if they help:

All of our orbits will be in Earth orbit, we’re effectively simulating natural and man-made satellites in various earth-based orbits. The man-made satellites will be under player control, but here’s where it gets tricky, we want to randomly spawn in things like asteroids. These things don’t have to affect one another, but it’d be a huge bonus if they did, and if they also affected the man-made satellites orbiting as well.

So this kind of simplifies things, but at the same time not so much. We’d like to use the inbuilt PhysX engine of Unreal to reduce the overhead and greatly simplify collision handling and what-not, but is it more efficient for us to use non-rigid bodies and just move them manually through our own equations? Currently all we’re doing is applying force, after giving something an initial velocity and both objects a mass.

hey everybody,
im trying to create something similar to what you do and i want to share my progress with you, because i kinda got something to work what you try to do. I made a physics based space ship fly thingie with trajectories like ksp, with SOIs and so on. The difficult part is the trajectory plotting, as you figured out, too. but here some screenshots of what i made:


The ship is in the SOI of the moving planet earth and is pulled to it by gravity. The trajectory is drawn by debug points where the ship will be in the next seconds. every point is one second. the problems i have are, that the trajectory isnt exact, you can see it in the second picture. it should be a ellipse but is is some kind of spiral towards the earth. the ship does fly in a ellipse but the trajectory isnt correct. it is all with blueprints. maybe i can help you with that, or you can help me with my problems.

ps: you can also see, that it works with every physical object, like the asteroid in the picture, because the force is implemented in the SOI, not in the physical objects.

cheers

When you target with your grande :

Hi!

Sorry for bringing this back up, but maybe some of you here have a clue what is going on with this:

I’m predicting a trajectory:

X = StartX + Velocity.X * Time
Y = StartY + Velocity.Y * Time
Z = StartZ + Velocity.Z * Time + (Gravity * (Time^2))/2

and compare the predicted with the resulting trajectory. The resulting trajectory seems to have some additional gravitational effect. The longer time I predict the more the z value derives from the actual resulting z value.

Any ideas what could play into adding to the gravitation here?

Edit:Aff, found it >.<.

LinearDamping was set on the static mesh.

Edit2:
though now it get’s interesting as to how to account for lineardamping…

and
https://developer.nvidia.com/sites/default/files/akamai/physx/Manual/RigidDynamics.html

aren’t much help… How often do physx updates occur…?

You can check my math but for folks to see an example of this formula in blueprints:

OK smarter Unreal Developers than me…

I have the same problem. The dots that need to get connected are the gravity force I think. I am just typing in values in the gravity variable to experiment. In my game, gravity and achieving orbit WORKS! I can get my trajectory line close with this formula:

X = StartX + Velocity.X * Time
Y = StartY + Velocity.Y * Time
Z = StartZ + Velocity.Z * Time + (Gravity * (Time^2))/2

But I am manually typing in my gravity force.

It should be just math, and therefore exact if we can get the correct arrangement of values.

Here is what I have:

  • Gravity only between Pawn and Sphere in space (simplified gravity).
  • No dampening which. To confirm, I display velocity, which is constant without input.
  • Overlapping a radius around sphere subjects the pawn to its constant gravity using a Radial Force Component.
  • Radial Force has a force of negative 75 Million (that’s what it takes!)

Gravity works with this setup. I can indeed achieve orbit, but I cannot get the trajectory line calculation to be precise.

To get the trajectory points, I ForEach through a 20 Item Array of time variables which goes into Time in the equation. Maybe this introduces issues as well?

Entire BP is here: