Game Development Community

Asteroids style control

by Joshua "RegularX" Birk · in Torque Game Builder · 04/26/2005 (6:03 am) · 6 replies

I think I'm missing an example here on how to make a player move like asteroids or the old Atari game "Combat" as opposed to a horizontal/vertical shooter (in fact, isn't there a Combat clone laying around here?)

It seems like there's a method I'm flaking on. Does something like .setImpulseForce() merely add velocity in the direction the player is "facing" ?

And as for shooting, I poked at it last night, but might this basic method?

- Mount point to "tip" of player sprite
- On "fire", set rotation to be equal to that of the player sprite
- set velocity in the same way that the player's "forward" function would work.

#1
04/26/2005 (6:09 am)
Hi Joshua,

You'll want to look at %obj.setImpulseForcePolar( %angle, %force) - that should do what you want for both your player and bullet movement. And yeah, your basic method for shooting should do the trick :)
#2
04/26/2005 (6:13 am)
Gosh darnit, if I had just paid better attention to Melv's force code, I think that would have been evident :)

Thanks for the speedy answer Chris.
#3
04/26/2005 (6:22 am)
Feel free to poke through my Biplane Battle code as well for anything you may find useful:

www.philspcmods.com/T2D/biplanebattle-beta1-source.zip

This was my first pass at the code, and although I've tidied up my code recently, this version is a bit messy and not that great. Still, it was my first project in T2D, and to be honest, the first real game that I'd made.
#4
04/26/2005 (1:05 pm)
I actually did an asteroids clone for my initial test of T2D.
Link removed due to bandwidth troubles. If you would like the file, then please inform me and I will email you a link to it
#5
04/27/2005 (5:22 am)
Bizarre internet problems are making it hard for me to glance at code (and posting) :| But I did get it mostly working last night. One quick question - how are you guys capping the velocity of a player? I tried "reseting" the Impulse to getRotation,0 before increasing it agian, but that didn't seem to work. And I tried setting both Linear velocities to zero, but that just stops it dead.
#6
04/27/2005 (12:42 pm)
Capping as in limiting the speed?

If that's what you are asking, then the solution is rather simple:
$player.setMaxLinearVelocity( 20 );     // Change the 20 until desired results