Game Development Community

dampen as a friction illusion

by rennie moffat · in Torque Game Builder · 11/10/2009 (1:06 pm) · 2 replies

Hi I am building some controls which are very similar to the astroids controls. Anyhow I want my player to "slide slightly, like they do in with the ShipMovement.cs (TGB). My code is provided below. Anyhow, The only difference between what I have written and the TGB version is that the TGB version, the object "slides" a bit after release of a directional button, so it kind of looks like he is on ice.


I, 1) installed a dampen behavior field and 2) set it in onAddBehavior, like the TGB version but nothing. Am I missing something? I can relate this to other spatial and physics methods which so far I have had trouble getting to run as I would expect.



if(!isObject(Spacer3000Controls))
{
	%template = new behaviorTemplate(Spacer3000Controls);
	
	%template.friendlyName = "Spacer3000 Controls";
	%template.behaviorType = "Player Input";
	%template.description = "Spacer3000 Controls";
	
	%template.addBehaviorField(upKey, "Controls Up Movement", keybind, "keyboard up");
	%template.addBehaviorField(downKey, "Controls Up Movement", keybind, "keyboard down");
	%template.addBehaviorField(leftKey, "Controls Left Movement", keybind, "keyboard left");
	%template.addBehaviorField(rightKey, "Controls Right Movement", keybind, "keyboard right");
	
	%template.addBehaviorField(moveSpeed, "speed of object up", float, 100);	
	%template.addbehaviorField(turnSpeed, "speed of turn", float, 30);
	%template.addbehaviorField(damping, "dampen amount", float, 1);
}

function Spacer3000Controls::onBehaviorAdd(%this)
{
	if(!isObject(moveMap))
	return;
	
	%this.owner.enableUpdateCallback();
	%this.owner.setDamping(%this.damping)
				
	moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "moveUp", %this);
	moveMap.bindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), "moveDown", %this);
	moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveleft", %this);
	moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "moveRight", %this);


	
	%this.up = 0;
	%this.down = 0;
	%this.left = 0;
	%this.right = 0;
}

function Spacer3000Controls::onUpdate(%this)
{
	%this.owner.setLinearVelocityPolar(%this.owner.rotation, (%this.down - %this.up) * %this.moveSpeed);
	%this.owner.setAngularVelocity((%this.right - %this.left) * %this.turnSpeed);
}

function Spacer3000Controls::moveUp(%this, %val)
{
	%this.up = %val;
}

function Spacer3000Controls::moveDown(%this, %val)
{
	%this.down = %val;
}

function Spacer3000Controls::moveLeft(%this, %val)
{
	%this.left = %val;
}

function Spacer3000Controls::moveRight(%this, %val)
{
	%this.right = %val;
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
11/11/2009 (6:06 am)
Here are the useful tips about physics in torque.
http://www.garagegames.com/community/forums/viewthread/95465
#2
11/11/2009 (11:59 am)
thank you.


;]