4 registered members (dBc, clonman, TipmyPip, 1 invisible),
19,019
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Precalculate an objects path and interaction
#260060
04/08/09 18:14
04/08/09 18:14
|
Joined: May 2008
Posts: 150 Switzerland
Hitsch
OP
Member
|
OP
Member
Joined: May 2008
Posts: 150
Switzerland
|
Hi,
I'm trying to precalculate where an object will be in the future, knowing it's speed, mass and direction, without the scene changing. Essentially how it's often used in other games to show what path a hand grenade is going to take if it's being thrown with a certain speed and angle. It would then follow exactly this path when it's released.
Since the present scene should not be changed, I would somehow have to precalculate the physics in the background and only the particles showing the path have to update when the variables change. The way I'm going to use this the physics in the "present" would not change, so the game is actually paused and only the camera can move around, the variables can be changed and the particles adjust.
I've worked with Gamestudios native physics engine and looked into Newton a bit, but I don't see how I could get this to work. I think I'm going to go with Newton though, because the calculations would have to be very precise. If two paths show that the two object will collide at a certain point in time and space, they would collide just like that afterwards.
Has anyone got a good suggestion where to start with this?
so long...
|
|
|
Re: Precalculate an objects path and interaction
[Re: Hitsch]
#260090
04/08/09 20:55
04/08/09 20:55
|
Joined: Jan 2004
Posts: 2,062 Hamburg, Germany
slacer
Expert
|
Expert
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
|
Hi Hitsch, if you throw an object you can calculate its expected path as you did at school ( google for Wurfparabel, schiefer Wurf, etc.) If two player throw an object and you want to know if and where both object meet in space and when, you would have to decrease delta t if both objects gets closer. This way you would not miss the moment you are looking for. But if you want to create a game where you have to throw objects and you only want to give the player a hint where his stone will hit the ground, you can work with a little trick. I used a paint program to create a sprite with an rainbow like arc. It was for a game with a catapult used to throw heavy objects around the area - to hit moving targets  Place the sprite in your 3D space in a way that one side of the arc meets your weapons starting point (the catapult). If you rotate the weapon to left or right, you can rotate the sprite also. If you want to put more energy into the impulse to throw the object, you scale the sprite along the X-direction. Once I found the right scaling factor depending on the energy choosen by the player (hold the trigger longer, loads more energy into the catapult), it worked perfectly. Well, it was too easy to aim then. So we decided to skip this feature... You have to decide if you really need to show the path of several objects and to test if they might hit somewhere in the air, or if this would kill the fun part of your game if the player knows the result before the event happens. -- slacer
|
|
|
Re: Precalculate an objects path and interaction
[Re: slacer]
#260097
04/08/09 21:24
04/08/09 21:24
|
Joined: May 2008
Posts: 150 Switzerland
Hitsch
OP
Member
|
OP
Member
Joined: May 2008
Posts: 150
Switzerland
|
Thx for your ideas Slacer. It sounds like a really good way to give the player a rough idea where the object is going to go. And this might be the way it's done in many games now that I think about it. It's often not very accurate though. Now my game mechanic is based on the players ability to make objects hit in midair and then bounce off the way he intends to. Kind of like orchestrating a physics event beforehand and when everything is set and ready, it plays out just like the player intended. For that he's able to stop time, move back and forward in time, move around in space to observe and organize collisions,. He can can then go back to where the path originates and change the variables there, resulting in a different outcome. or if this would kill the fun part of your game if the player knows the result before the event happens I thought that too when I watched different physics game. Knowing that you are going to hit the target perfectly and then seeing it happening is not much fun. But if you could construct a very complex and very fast event that you could not create in real time, then I think it would be a nice moment when you see your creation play out. Kind of like that Ati Demo from a few years back, where hundreds of balls fly all around the scene and hit different instruments and you totally lose track of whats happening. But it looks amazing. Now Calculating a simple path with simple math as you described sounds nice but would be way to complicated and I'm not sure if the engine would calculate exactly the same or be less (or more) accurate. Is it possible to speed up time in general? So the physics could play out and I could record the paths and then move frame by frame, back and forward?
Last edited by Hitsch; 04/08/09 21:33.
|
|
|
Re: Precalculate an objects path and interaction
[Re: Hitsch]
#260104
04/08/09 22:09
04/08/09 22:09
|
Joined: Jan 2004
Posts: 2,062 Hamburg, Germany
slacer
Expert
|
Expert
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
|
Is it possible to speed up time in general? So the physics could play out and I could record the paths and then move frame by frame, back and forward?
You can create a bunch of arrays and store each objects position and angle at a rate of 20 fps and use these arrays to show the objects trails or to show the situation at frame 200 and rotate the camera around the center of action. This way your get something like the bullet time effect  You could use motion blur for sequences of the past and only render outlines of objects from the future. But it is not easy to speed things up. Why? If you have an object with a mass of 1 kg and you want to apply a force to it, a single frame of energy would not be enough. You would have to apply the force for several frames until the friction, etc. does not hold back the object from moving. If you increase the energy of that impulse to shorten the time needed to get your object into the air, your object might launch like a bullet from a gun or like a rocket but is not similar to a thrown stone. It is a realtime physics engine. But I think there was a time variable which has an effect on the physics engine, maybe you can play around with it and prerecord the sequence without even rendering a single frame. Just check the manual if there is a reference to physic simulation and time, fps, fps_max, etc. There was a time related bug some years ago with ODE and it was fixed with such a time correcting variable... maybe it could help you now, too. -- slacer
|
|
|
Re: Precalculate an objects path and interaction
[Re: slacer]
#260408
04/10/09 15:31
04/10/09 15:31
|
Joined: May 2008
Posts: 150 Switzerland
Hitsch
OP
Member
|
OP
Member
Joined: May 2008
Posts: 150
Switzerland
|
I have a working scene now with ODE. I'm throwing an object and tracing it's steps with particles. When I then launch an other object of exactly the same masses, it follows that path remarkably well. The first few objects follow exactly, then they slowly tend to leave the path. As expected I guess... And yes, that's all because of the frame rate that is dropping. So like this it's impossible to get the same result from a calculation as the last time. They will always be slightly different  So what I would need is to have the physics engine do its calculations not in real time, but take as long as it needs for my desired amount of accuracy. So far I couldn't find a way to do this in ODE, since "ph_fps_max_lock = 60" restricts the engine only for higher frame rates, but not if they drop below the fps_min. Could this be possible with Newton? So that I can give it a bunch of variables and only get the update when the whole scene has played out. Or have regular updates, but just not dependent on the frame rate?
|
|
|
|