Movement bug????
by Zachery Walsh · in Torque Game Builder · 04/27/2010 (11:53 pm) · 3 replies
Hey,
I have this game called FREEFALL! and is a game where a character falls and avoids hitting any crazy object on the way down?
but one of the bugs i have is in my code for movement.
problem is the charachter moves correctly
but if player holds down on move keys when they die by colliding with anything in the environment the gui pops up disable's the controls and the charachter is still moving, even though the player isn't pressing anything?
HERE IS THE CODE???
___________________________________________________________________________________________________________-----------------------------------------------------------------------------------------------------------___________________________________________________________________________________________________________
//create new actionmap to hold keybinds
new actionmap(keys);
//bind keys to action map
keys.bindcmd("keyboard","w","deccel();","stopmove();");
keys.bindcmd("keyboard","s","accel();","stopmove();");
keys.bindcmd("keyboard","a","moveleft();","stopmove();");
keys.bindcmd("keyboard","d","moveright();","stopmove();");
//push to activate pop to deactivate
keys.push();
//movement functions called in the keybinds
function deccel()
{
player.setlinearvelocityY(20);
}
function accel()
{
player.setlinearvelocityY(50);
}
function moveleft()
{
player.setlinearvelocityX(-50);
}
function moveright()
{
player.setlinearvelocityX(50);
}
function stopmove()
{
player.setlinearvelocity(0,30);
}
function player::oncollision(%this,%other)
{
//check to see if player touches grass
if(%other.class $= grassclass)
{
//disable the keys binds
keys.pop();
//stop the player moving
player.setlinearvelocity(0,0);
//pull back up the menu
winscreen.setvisible(1);
titlescreen.setvisible(1);
playbutton.setvisible(1);
quitbutton.setvisible(1);
//reset the players position
player.setposition(1.828,-17.172);
}
___________________________________________________________________________________________________________-----------------------------------------------------------------------------------------------------------___________________________________________________________________________________________________________
I have this game called FREEFALL! and is a game where a character falls and avoids hitting any crazy object on the way down?
but one of the bugs i have is in my code for movement.
problem is the charachter moves correctly
but if player holds down on move keys when they die by colliding with anything in the environment the gui pops up disable's the controls and the charachter is still moving, even though the player isn't pressing anything?
HERE IS THE CODE???
___________________________________________________________________________________________________________-----------------------------------------------------------------------------------------------------------___________________________________________________________________________________________________________
//create new actionmap to hold keybinds
new actionmap(keys);
//bind keys to action map
keys.bindcmd("keyboard","w","deccel();","stopmove();");
keys.bindcmd("keyboard","s","accel();","stopmove();");
keys.bindcmd("keyboard","a","moveleft();","stopmove();");
keys.bindcmd("keyboard","d","moveright();","stopmove();");
//push to activate pop to deactivate
keys.push();
//movement functions called in the keybinds
function deccel()
{
player.setlinearvelocityY(20);
}
function accel()
{
player.setlinearvelocityY(50);
}
function moveleft()
{
player.setlinearvelocityX(-50);
}
function moveright()
{
player.setlinearvelocityX(50);
}
function stopmove()
{
player.setlinearvelocity(0,30);
}
function player::oncollision(%this,%other)
{
//check to see if player touches grass
if(%other.class $= grassclass)
{
//disable the keys binds
keys.pop();
//stop the player moving
player.setlinearvelocity(0,0);
//pull back up the menu
winscreen.setvisible(1);
titlescreen.setvisible(1);
playbutton.setvisible(1);
quitbutton.setvisible(1);
//reset the players position
player.setposition(1.828,-17.172);
}
___________________________________________________________________________________________________________-----------------------------------------------------------------------------------------------------------___________________________________________________________________________________________________________
About the author
Game Design Student Artist / Half Descent Programmer
#2
Which is the section of the code i need to pay attention
your right that i need to put in an extra detection to see if the player is holding down a button.
updateMovement function ...???
put the updateMovement()
here:
function player::oncollision(%this,%other)
{
//check to see if player touches grass
if(%other.class $= grassclass)
{
//disable the keys binds
keys.pop();
before the keys pop ????
or HERE:
//movement functions called in the keybinds
function deccel()
{
player.setlinearvelocityY(20);
}
function accel()
{
player.setlinearvelocityY(50);
}
function moveleft()
{
player.setlinearvelocityX(-50);
}
function moveright()
{
player.setlinearvelocityX(50);
}
function stopmove()
{
player.setlinearvelocity(0,30);
}
04/28/2010 (9:47 pm)
So...Which is the section of the code i need to pay attention
your right that i need to put in an extra detection to see if the player is holding down a button.
updateMovement function ...???
put the updateMovement()
here:
function player::oncollision(%this,%other)
{
//check to see if player touches grass
if(%other.class $= grassclass)
{
//disable the keys binds
keys.pop();
before the keys pop ????
or HERE:
//movement functions called in the keybinds
function deccel()
{
player.setlinearvelocityY(20);
}
function accel()
{
player.setlinearvelocityY(50);
}
function moveleft()
{
player.setlinearvelocityX(-50);
}
function moveright()
{
player.setlinearvelocityX(50);
}
function stopmove()
{
player.setlinearvelocity(0,30);
}
#3
Every movement function should call updateMovement. For example:
function deccel()
{
player.deccel=true;
player.updateMovement();
}
04/29/2010 (4:55 am)
Follow the example in the fish game. Do you have that tutorial?Every movement function should call updateMovement. For example:
function deccel()
{
player.deccel=true;
player.updateMovement();
}
Torque Owner Kevin James
function PlayerFish::updateMovement(%this) { if(%this.moveLeft) { $FishPlayer.setFlipX(true); $FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed ); } if(%this.moveRight) { $FishPlayer.setFlipX(false); $FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed ); } if(%this.moveUp) { %this.setLinearVelocityY( -$FishPlayer.vSpeed ); } if(%this.moveDown) { %this.setLinearVelocityY( $FishPlayer.vSpeed ); } if(!%this.moveLeft && !%this.moveRight) { %this.setLinearVelocityX( 0 ); } if(!%this.moveUp && !%this.moveDown) { %this.setLinearVelocityY( 0 ); } }This will fix it when a player dies while holding down a movement key.