Help with game physics
by bentgarney · in Torque Game Builder · 03/03/2005 (3:19 am) · 6 replies
#2
You can generate fxSceneObject2D objects. They have all of the core-features of the T2D objects (including collision-detection and physics) but don't render anything.
What use are these then I hear you ask?
Well, they become very useful when you want objects to be moved in groups or in some certain geometric pattern. I can create one and mount visible objects like sprites to it.
For instance, say I wanted an object to orbit in a circle. I could mount some objects to the invisible fxSceneObject2D and rotate it so that my mounted objects orbit. There's also a much nicer way to do this called "setAutoMountRotation()" which actually rotates the mount-points themselves (not the underlying object) and this is used for the "helpers" in the shooter demo.
You can use "fxSceneGraph2D::onUpdateScene()" which is called per-frame although be careful ow much stuff you do here as you'll hurt performance of your game otherwise. Also, you can use SimSets/SimGroups to maintain lists of arbitrary objects.
So many ways to do stuff. :)
Hope this helps,
- Melv.
03/03/2005 (4:10 am)
Just to let you guys know something that may be of use..............You can generate fxSceneObject2D objects. They have all of the core-features of the T2D objects (including collision-detection and physics) but don't render anything.
What use are these then I hear you ask?
Well, they become very useful when you want objects to be moved in groups or in some certain geometric pattern. I can create one and mount visible objects like sprites to it.
For instance, say I wanted an object to orbit in a circle. I could mount some objects to the invisible fxSceneObject2D and rotate it so that my mounted objects orbit. There's also a much nicer way to do this called "setAutoMountRotation()" which actually rotates the mount-points themselves (not the underlying object) and this is used for the "helpers" in the shooter demo.
// Create our invisible solar-system.
%solarSystem= new fxSceneObject2D() { scenegraph = myscenegraph; };
%solarSystem.setSize( 10 );
// Mount a planet to the solar-system.
%planet1 = new fxStaticSprite2D() blah blah blah;
%planet1.mount( %solarSystem, "1 0" );
// Mount another planet to the solar-system.
%planet2 = new fxStaticSprite2D() blah blah blah;
%planet2.mount( %solarSystem, "0 2" );
// Rotate our solar system with this....
%solarSystem.setAutoRotation( 90 );
// ... or we could use this instead...
%solarSystem.setAutoMountRotation( 90 );You can use "fxSceneGraph2D::onUpdateScene()" which is called per-frame although be careful ow much stuff you do here as you'll hurt performance of your game otherwise. Also, you can use SimSets/SimGroups to maintain lists of arbitrary objects.
So many ways to do stuff. :)
Hope this helps,
- Melv.
#3
Another thing fxSceneObject2D seems would be good for are the T2D equivilant of TGE "triggers"
03/03/2005 (7:25 am)
Ahhh... your too clever Melv lol... that what the ships in the shooter demo are following ? (especially when you die and their target shoots up)Another thing fxSceneObject2D seems would be good for are the T2D equivilant of TGE "triggers"
#4
You could use the fxSceneObject2D for something equivalent to a trigger but I've got on my TODO list, a 2D trigger object. Don't ask when though. :)
- Melv.
03/03/2005 (9:17 am)
If I remember correctly, I just apply some constant forces to all the enemy when you die and set a world-limit high above the scene to kill them, that's all.You could use the fxSceneObject2D for something equivalent to a trigger but I've got on my TODO list, a 2D trigger object. Don't ask when though. :)
- Melv.
#5
Edit: Sweet! And just in case it wasn't mentioned, you can set the initial position of the mount points by setting the rotation of the "origin" object. I randomized it like this:
03/03/2005 (9:20 am)
Quote:For instance, say I wanted an object to orbit in a circle. I could mount some objects to the invisible fxSceneObject2D and rotate it so that my mounted objects orbit.Hey, that's just what I did to get my moon going across the sky. :) But I'm going to try out this autoMountRotation stuff.
Edit: Sweet! And just in case it wasn't mentioned, you can set the initial position of the mount points by setting the rotation of the "origin" object. I randomized it like this:
$arenaMoonOrigin.setRotation( getRandom() * 360 );That way the objects mounted don't always start in the same spot around the origin.
#6
03/03/2005 (9:28 am)
I did looping planes with autoRotation and a schedule to apply force to keep them moving, but mounting them on something else would be a definate option for the future. Especially if you need to move multiple objects around the same centre point.
Torque Owner Philip Mansfield
Default Studio Name
There's no performance hit that I can see, and using the onUpdate call (to update stuff every frame) is more likely to kill your performance than the scheduling tasks (from what I've read - haven't actually tired it).
Providing you tinker with how often the schedule is called (every 100ms produces a more than smooth enough circular movement for my needs) you should be able to get what you want.
Can't help with the list keeping aspect I'm afraid.