Game Development Community

Asteroids Ship Movement

by Erick Grove · in Torque Game Builder · 02/15/2006 (8:26 am) · 8 replies

Hi all

I know this is a serious noob question, but how would one perform the movement for the ship in an asteroids type game, with angular velocity etc.. ?

Thanks

Erick

#1
02/15/2006 (8:41 am)
Check out setLinearVelocityPolar()

e.g
%ship.setLinearVelocityPolar(%angle,%speed);
#2
02/15/2006 (8:42 am)
Oh man, that simple eh ?

*slaps forhead*

Thanks so much.
#3
02/15/2006 (9:16 am)
I am trying this out, but does not seem to be working too well.

Can anyone help with this ?

function playerUp()
{
	$player.setImpulseForcePolar($playerAngle,5,true);
}

function playerLeft()
{
	$playerAngle = $playerAngle + 10;
}

function playerRight()
{
	$playerAngle = $playerAngle - 10;
}
#4
02/16/2006 (7:24 am)
@David

I tried that function out and while it gave me movement, it was not behaving like an asteroids ship. I realise that more needs to be done to achieve that, but I am just lost as to how.

Can someone please check out the code above ?
#5
02/18/2006 (7:44 am)
Aha! Finally something I can help with. :)
I wrote this code and tested it out. You need to use a schedule with playerForward since you want acceleration to continue as long as they hold down the up key. the schedule gets cancelled once they let go of the up key. If you have any questions with this code please ask.


$player.turnSpeed = 150;
$player.moveSpeed = 1;

function playerForward()
{
		
	$player.setImpulseForcePolar($player.getRotation(), $player.moveSpeed);
	$playerForwardSchedule = schedule(10, 0, playerForward);
	
}

function playerForwardStop()
{
	cancel($playerForwardSchedule);	
	
	
	
}

function playerTurnRight()
{
	$player.setAngularVelocity( $player.turnSpeed );
	
	
	
}
function playerTurnRightStop()
{
	$player.setAngularVelocity(0);	
	
}

function playerTurnLeft()
{
	
	$player.setAngularVelocity(-$player.turnSpeed);	
	
}

function playerTurnLeftStop()
{
	$player.setAngularVelocity(0);
		
	
}
#6
02/18/2006 (7:47 am)
Also your ship graphic needs to be facing upwards to start off with so the rotations are right.
#7
02/18/2006 (9:55 pm)
This works perfectly !

Thanks so much for your help !
#8
02/19/2006 (6:04 am)
Just glad I could finally give back to the t2d community :P