Platform Mechanincs Player Movement Help
by rennie moffat · in Torque Game Builder · 08/07/2009 (10:45 am) · 2 replies
Hi, I have tried to add the mechanics of the player from the PlatformMechanics tutorial. I have copy and pasted while reading along and grasping all that I read. However it just crashes my game. So I have included the code, if you have a minute, please go over the code to see if you can find any errors because I am stumped.
edit:
as of 6.01pm friAug7th I edited this copy from Advice Tim's eagle eye. and it Loads now but no movement on the playerClass. I was expecting to see my player not animate, but move.
thank you
edit:
as of 6.01pm friAug7th I edited this copy from Advice Tim's eagle eye. and it Loads now but no movement on the playerClass. I was expecting to see my player not animate, but move.
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%this.setCollisionMaxIterations(2);
%force = 20;
sceneWindow2D.mount($pGuy, "0 0", %force, true);
}
function playerClass::updateHorizontal(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}
if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
if(!%this.airborne)
%this.setLinearVelocityY(0);
}
function playerClass::updateVertical(%this)
{
%yVelocity = %this.getLinearVelocityY();
if(%this.airborne)
{
%this.setLinearVelocityY(0);
%collision = %this.castCollision(0.005);
if(%collision !$= "")
%this.setLinearVelocityX(0);
}
%this.setLinearVelocityY(100);
%collision = %this.castCollision(0.005);
if(%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
}
else if(%yVelocity < 0 && %this.airborne)
{
%this.setConstantForceY(100);
}
else
{
%this.airborne = false;
%this.setConstantForceY(0);
}
%this.setLinearVelocityY(%yVelocity);
}
function playerClass::updateMovement(%this)
{
%this.updateHorizontal();
%this.updateVertical();
}
function playerJump()
{
if(!$pGuy.airborne)
{
$pGuy.setLinearVelocityY(-225);
$pGuy.airborne = true;
}
if(%this.airborne)
{
%this.setLinearVelocityY(0);
%collision = %this.castCollision(0.005);
if(%collision !$= "")
%this.setLinearVelocityX(0);
}
if(%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
}
else if(%yVelocity < 0 && %this.airborne)
{
%this.setConstantForceY(100);
}
}
function PlatformerSceneGraph::onUpdateScene()
{
if (isObject($pGuy))
$pGuy.updateMovement();
else
{
%this.airborne = false;
%this.setConstantForceY(0);
}
}thank you
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.
#2
I did make your adjustments to a tee and it loads now, but no movement takes place. I was expecting the player to move.
not sure what to do.
08/07/2009 (3:06 pm)
ok thanks.I did make your adjustments to a tee and it loads now, but no movement takes place. I was expecting the player to move.
not sure what to do.
Torque Owner Timothy Castagna
TK Games LLC
there are 2 of function playerClass::onLevelLoaded(%this, %scenegraph)
function playerJump() { if(!$pGuy.airborne) { $pGuy.setLinearVelocityY(-225); $pGuy.airborne = true; } } if(%this.airborne) { %this.setLinearVelocityY(0); %collision = %this.castCollision(0.005); if(%collision !$= "") %this.setLinearVelocityX(0); } if(%collision $= "wall") { %this.airborne = true; %this.setConstantForceY(100); } else if(%yVelocity < 0 && %this.airborne) { %this.setConstantForceY(100); }should read
function playerJump() { if(!$pGuy.airborne) { $pGuy.setLinearVelocityY(-225); $pGuy.airborne = true; } if(%this.airborne) { %this.setLinearVelocityY(0); %collision = %this.castCollision(0.005); if(%collision !$= "") %this.setLinearVelocityX(0); } if(%collision $= "wall") { %this.airborne = true; %this.setConstantForceY(100); } else if(%yVelocity < 0 && %this.airborne) { %this.setConstantForceY(100); } }this
function PlatformerSceneGraph::onUpdateScene() { if (isObject($pGuy)) $pGuy.updateMovement(); } else { %this.airborne = false; %this.setConstantForceY(0); }should read
function PlatformerSceneGraph::onUpdateScene() { if (isObject($pGuy)) $pGuy.updateMovement(); else { %this.airborne = false; %this.setConstantForceY(0); } }just a couple things out of place it seems.