Advertisement

Trajectory line indicator discussion

Started by April 01, 2024 08:34 PM
7 comments, last by JoeJ 8 months, 2 weeks ago

Hi,

Imagine you're writing a mechanic in which player can throw an object. Main requirement for this mechanic is a trajectory line indicator which will show the travel path and the landing point.

Two valid approaches come to my mind - I'll call them physics based approach and fixed path approach.

The physics based approach basically means calculating the travel path using parameters such as force, gravity, initial direction etc. in order to find the travel path of the object.
The fixed path approach is where we draw the path first (can be bezier curve or anything that can generate a curve that can be sampled) and then we move the object along the generated path.

What approach would you use and why? Do you see any other valid approach to this problem? Which approach do you think is used the most in video games? Did you implement such mechanic in any of your shipped titles?

I assume that the physics based approach would be desirable in a simulation type games such as World of Warships? Any game that is heavily physics based would probably do it that way? Although it seems quite hard to implement and even harder when we would like to include the bounce trajectories.

Fixed path approach seems more flexible? Generated path can be more than a curve (can be anything really) also seems easy to use for designers. Shouldn't it be more precise than physics based approach if we assume that the projectiles are traveling in high speed and high range? Bounce trajectory seems to be easier to implement this way as well, since we can detect obstacles along the generated path and generate new path from the bounce point? Do you think that games that seems to be relying on physics would go for such shortcut?

Please let me know what you think and point out any flaws in my thinking.

Thank you, and have a great day!

None

jakubkrol1994@gmail.com said:
What approach would you use and why?

If there is no air resistance affecting the object, gravity is the only external force and so the trajectory is a parabola.
Thus you can aim and predict for a target analytically, draw the trajectory exactly, and if you use a physics engine for the actual projectile the integration error is usually small enough to ignore it.

Advertisement

There is no choice: if the indicator is supposed to be accurate, it has to compute exactly the same trajectory and point of impact as the simulation of the actually thrown object. You have to simulate throwing the object, with more or less “physics based” calculations, measure how it moves and turn those collected points into a trajectory preview.

You can only attempt to be cheap if the simulation allows it: even in the simple case JoeJ discusses, uniform gravity and initial velocity without angular momentum and without air resistance, there can be many types of unmanageable differences between advancing integration and collision detection frame by frame and intersecting the analytic parabola with level geometry.

Omae Wa Mou Shindeiru

LorenzoGatti said:
even in the simple case JoeJ discusses, uniform gravity and initial velocity without angular momentum and without air resistance

Angular momentum does not affect the linear trajectory, but linear damping might a bit. If enabled, that's the same as air resistance, so i would turn it off for the projectile body.

It also depends on the integrator and timestep a lot ofc.
I have used a physics engine with RK4 integrator, and the projectile followed the predicted parabola very precisely. For a distance of 100m, the error was in the range of centimeters.

LorenzoGatti said:
You have to simulate throwing the object, with more or less “physics based” calculations, measure how it moves and turn those collected points into a trajectory preview.

I would not say that. Even if you need 100% accuracy and are willing to pay the cost, you likely can't predict the future of all other objects in the scene, which might then still cause unexpected collisions in rare cases anyway, so i don't see a reason to pay the cost.

I also assume the indicator is mainly used to assist aiming, but things like predicting moving targets or moving obstacles are left to the player.

I did a code example recently btw: https://www.gamedev.net/forums/topic/715283-aiming-feature-like-angry-bird/5460529/

Jikoob said:
What approach would you use and why? Do you see any other valid approach to this problem? Which approach do you think is used the most in video games? Did you implement such mechanic in any of your shipped titles?

I think it needs the approach that feels right to the game. If the purpose is to challenge the player in delivering the object exactly there, you get a whole different setup than if the purpose is more story-oriented, and throwing the object is just a visualization of the narrative.

As to other approaches, my thoughts are running wild. A rectangular trajectory could be fun, throw it up, and the wind carries it in? A parabola is sooo common 🙂

Don't know. I guess physics based, because everybody seems to have physics these days.

Nope.

Alberth said:
Don't know. I guess physics based, because everybody seems to have physics these days. Nope.

Sounds you do not really like the boredom from attempting to simulate reality?

I think it's good in general. Because, if things behave realistically, the player can apply real world experience to make predictions. And predictions are essential to make action games work at all. I could not make much sense out of a rectangular trajectory maybe, or it would take me too much time to learn it, causing frustration. But if the trajectory as a boring parabola, i can predict and don't need to learn anything. It just works, and likely what makes the game interesting is something else, but not really the shape of trajectories.

Super Mario is a good example. There were surely earlier games which introduced acceleration, but it's just the perfect action game. It still uses constant velocity movement for most enemies. This eases gameplay, because the players skills are already taxed with predicting Marios accelerating trajectory. So the simple enemy movement makes it easier and more fun to predict the whole game.
But the interesting thing is Marios movement, based on controlling acceleration instead velocity. This introduces lag. Usually we don't like lag, but here we do, simply because it behaves like in the real world.
We could say the lag forces us to plan ahead, but we can also say it gives us more time to plan our strategy.
And this latter point is what makes the game great, and why we usually want to respect laws of physics in games.

That said to defend what's imo the sleeping princess of video games: Physics simulation. : )
If you think it's boring, then i assume you think so because currently physics is much too passive. Stacks of boxes, ragdoll deaths, even destruction - that's all passive stuff. We need more motors. Robotics, moving platforms, vehicles, etc. That's where the opportunity is, imo.

Advertisement

Thank you all for your answers!

@JoeJ I do agree, in most games I can see the physics based approach to be the way to go. Regarding your Super Mario example, I feel the same way for Half-Life 2 and source engine which brought a lot of physics play onto the playground which was awesome.

When narrowing down my question to the simple diagonal throw/free fall problem I do agree that the math here is not complicated and it's probably the best way to implement such mechanic. Since in most game engines now we use physics (applying force to a rigidbody) to throw something, it would be wise to use physics and math to actually calculate the travel path of the thrown object.

Although if I would have to make a boomerang throw mechanic with travel path indication in a isometric 2.5D game that doesn't really rely on physics, I think I would seriously consider writing a parametrized boomerang path generator and then simply move the boomerang along generated path.

Example of a boomerang path in a 3D space

None

Jikoob said:
When narrowing down my question to the simple diagonal throw/free fall problem I do agree that the math here is not complicated and it's probably the best way to implement such mechanic.

To me, the argument usually is: If the problem has an analytical solution, then i really want to use it. It's like free lunch.
Contrary, if i need to solve something iteratively, e.g. hitting a moving target, then i'm always a bit frustrated about the cost.

Jikoob said:
Regarding your Super Mario example, I feel the same way for Half-Life 2

Yeah, i always thought HL2 is the most innovative game ever, due to it's introduction of physics. (i've missed Trespasser)

But then, many years later, i started to play Super Mario because my wife likes it.
And i found out: Super Mario has done everything HL2 did long before. :D

This topic is closed to new replies.

Advertisement