Game Development Community

Problems modifying the asteroids control

by J Sears · in Torque Game Builder · 05/29/2007 (2:30 pm) · 2 replies

I found the asteroids controls script file on the TDN somewhere, was a very handy file and was a good start for what I wanted to do. So I've been playing with it trying to make some changes and ran into a strange problem that I'm not sure how I'm causing it.

The only part of the file I've been messing with so far is the onupdate part and have changed it to this.

if(%this.up == 1)
   {
      %this.owner.setConstantForcePolar(%this.owner.rotation, %this.owner.getConstantForce() + %this.acceleration);
    }
   
   if(%this.down == 1 && %this.owner.getConstantForce() > 0)
   {
          %this.owner.setConstantForcePolar(%this.owner.rotation, %this.owner.getConstantForce() - 4.0);
           if(%this.owner.getConstantForce() < 0)
	   %this.owner.setConstantForcePolar(%this.owner.rotation, 0);
   }
	
   	%this.owner.setAngularVelocity((%this.right - %this.left) * %this.turnSpeed);

now when I put in the asteroids controls unmodified and setup the object for it to work on it works exactly as expected. But now when I changed it to this it works exactly how I want in only the direction it starts off facing. If I rotate it it hardly moves no longer how long you hold down the up key, but then if I rotate it back to close to the starting position of the object it works as expected again.

Basically what I want to do is set up a simple car controls so I want up to be gas, eventually I'm going to set a max value for it. Down will be break, the way I want this to work is holding down will bring the car to a stop then if you release down and press it again from stopped it will go in reverse. I have a plan for that.

and rotation I'm going to eventually set up so that it has a more limited speed and that the rotation speed is based off of the vehicle speed so that you can't rotate it when stopped and then have the max turn speed increased as the car speed increases.

All that was just to give some background on what I'm trying to do. I looked at a lot of the force commands and it seems this is the one I want since I want to go backwards and forwards but I just can't get it to work correctly with the rotation.

#1
05/30/2007 (8:41 am)
Have you checked this out on TDN.
#2
05/30/2007 (10:38 am)
I hadn't come across that, that's pretty good stuff thanks