Confused with Miniplatformer...
by Keith Murphy · in Torque Game Builder · 07/14/2008 (8:55 pm) · 5 replies
Thank you for responding.
That's the first thing that I figured I did wrong. But I set it to "4" without any negative sign (or any other sign).
I'm baffled!
That's the first thing that I figured I did wrong. But I set it to "4" without any negative sign (or any other sign).
I'm baffled!
#2
07/15/2008 (12:44 pm)
When I said "gravity" what I really meant was "Constant Force Y", my bad.
#3
New Scene, using the sprites from the miniplatformer tutorial (ninja and so on)
1. Take a block and drag it to the bottom of the screen.
2. Take an animated sprite of the ninja, place him high over the block.
3. Editing the Ninja Sprite:
Name: player
Class: playerClass
Send Collision:Checked
Receive Collision: Not Checked
Send Physics: Checked
Receive Physics: Not Checked
Collision Layers: All
Collision Groups: All
Editing the Block Sprite:
Send Collision:Not Checked
Receive Collision: Checked
Send Physics: Not Checked
Receive Physics: Not Checked
Collision Layers: All
Collision Groups: All
Immovable: Checked
Now what I found is, depending on what I put for the following values, I got very different results.
Constant Force Y: 4.000
Gravtic: Not Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 1.000
Gravtic: Not Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 4.000
Gravtic: Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 4.000
Gravtic: Checked
Force Scale: 1.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work..
Constant Force Y: 4.000
Gravtic: Not Checked
Force Scale: 1.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 3.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is now stuck in the jumping down animation.
He still moves left or right, but can no longer jump.
Constant Force Y: 0.000
Gravtic: Not Checked
Force Scale: 3.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, just very high.
He lands, and it seems to work just fine.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 2.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 4.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, landing causes it to toggle again.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 5.000
The ninja drops and immediately goes into his rapid toggle dance as above.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
He does animate correctly when moving back and forth.
He does jump, just very high.
Jumping again proves that it is now working after the first jump.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 5.000
The ninja drops and immediately goes into his rapid toggle dance as above.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
He does animate correctly when moving back and forth.
He does jump, just very high.
Jumping again proves that it is now working after the first jump.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 6.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, landing causes it to toggle again.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 7.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
When I jump a 2nd time, he goes into his rapid dance again.
Help!
07/16/2008 (11:38 am)
I thought that maybe if I did this step my step, someone could point out my flaw. I'm having a heck of a time figuring this out.New Scene, using the sprites from the miniplatformer tutorial (ninja and so on)
1. Take a block and drag it to the bottom of the screen.
2. Take an animated sprite of the ninja, place him high over the block.
3. Editing the Ninja Sprite:
Name: player
Class: playerClass
Send Collision:Checked
Receive Collision: Not Checked
Send Physics: Checked
Receive Physics: Not Checked
Collision Layers: All
Collision Groups: All
Editing the Block Sprite:
Send Collision:Not Checked
Receive Collision: Checked
Send Physics: Not Checked
Receive Physics: Not Checked
Collision Layers: All
Collision Groups: All
Immovable: Checked
Now what I found is, depending on what I put for the following values, I got very different results.
Constant Force Y: 4.000
Gravtic: Not Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 1.000
Gravtic: Not Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 4.000
Gravtic: Checked
Force Scale: 0.000
The ninja hangs and doesn't drop at all.
Constant Force Y: 4.000
Gravtic: Checked
Force Scale: 1.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work..
Constant Force Y: 4.000
Gravtic: Not Checked
Force Scale: 1.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 3.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is now stuck in the jumping down animation.
He still moves left or right, but can no longer jump.
Constant Force Y: 0.000
Gravtic: Not Checked
Force Scale: 3.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, just very high.
He lands, and it seems to work just fine.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 2.000
The ninja drops, hits the block and stops there, but is stuck in the "dropping down" animation.
He does move left or right, but again only shows the dropping down animation when moving.
Jump does not work.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 4.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, landing causes it to toggle again.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 5.000
The ninja drops and immediately goes into his rapid toggle dance as above.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
He does animate correctly when moving back and forth.
He does jump, just very high.
Jumping again proves that it is now working after the first jump.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 5.000
The ninja drops and immediately goes into his rapid toggle dance as above.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
He does animate correctly when moving back and forth.
He does jump, just very high.
Jumping again proves that it is now working after the first jump.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 6.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, landing causes it to toggle again.
Constant Force Y: 0.000
Gravtic: Checked
Force Scale: 7.000
The ninja drops.
He does animate correctly when moving back and forth.
He does jump, now more normally.
He lands, but is caught toggling rapidly between the standing and dropping down animation.
Jump is unreliable, only working 50% of the time. (Assumingly when I hit it while he is standing)
When I jump again, he lands, and suddenly it seems to work just fine.
When I jump a 2nd time, he goes into his rapid dance again.
Help!
#4
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("./playerClass.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
07/16/2008 (11:38 am)
Here's my game.cs//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("./playerClass.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
#5
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$player = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%this.enableUpdateCallback();
}
function playerLeft()
{
$player.moveLeft = true;
}
function playerLeftStop()
{
$player.moveLeft = false;
}
function playerRight()
{
$player.moveRight = true;
}
function playerRightStop()
{
$player.moveRight = false;
}
function playerJump()
{
if(!$player.airborne)
{
$player.setLinearVelocityY(-150);
$player.airborne = true;
}
}
function playerClass::updateHorizontal(%this)
{
if (%this.moveLeft && %this.moveRight)
{
%this.setLinearVelocityX(0);
return;
}
if (%this.moveLeft)
{
if (!%this.againstLeftWall)
{
%this.againstRightWall = false;
%this.setLinearVelocityX(-30);
}
return;
}
if (%this.moveRight)
{
if (!%this.againstRightWall)
{
%this.againstLeftWall = false;
%this.setLinearVelocityX(30);
}
return;
}
if (!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
}
function playerClass::updateVertical(%this)
{
%yVelocity = %this.getLinearVelocityY();
%this.setLinearVelocityY(10);
%collision = %this.castCollision(0.005);
%normalX = getWord(%collision, 4);
%normalY = getWord(%collision, 5);
// no collision
if (%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
%this.setLinearVelocityY(%yVelocity);
return;
}
// collides with wall to the left
if (%normalX == 1 && %normalY == 0)
{
%this.againstLeftWall = true;
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// collides with wall to the right
if (%normalX == -1 && %normalY == 0)
{
%this.againstRightWall = true;
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// on ground with no wall collisions
if (%normalX == 0 && %normalY == -1)
{
%this.airborne = false;
%this.againstLeftWall = false;
%this.againstRightWall = false;
%this.setConstantForceY(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// in air and hits platform with head
if (%normalY == 1)
{
%this.airborne = true;
%this.setLinearVelocityX(0);
%this.setConstantForceY(100);
%this.setLinearVelocityY(%yVelocity);
return;
}
// in case another type of collision normal was detected
error("another collison type" SPC %normalX SPC %normalY);
%this.airborne = false;
%this.againstLeftWall = false;
%this.againstRightWall = false;
%this.setLinearVelocityY(%yVelocity);
}
function playerClass::onUpdate(%this)
{
%this.updateHorizontal();
%this.updateVertical();
%this.setCurrentAnimation();
}
function playerClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
%yVelocity = %this.getLinearVelocityY();
if (%xVelocity > 0)
{
%this.setFlip(false, false);
}
else if (%xVelocity < 0)
{
%this.setFlip(true, false);
}
if (%this.airborne)
{
if(%yVelocity < 0)
{
%this.playAnimation(PlayerJumpUpAnimation);
return;
}else
{
%this.playAnimation(PlayerJumpDownAnimation);
return;
}
}
if ($player.moveLeft == true || $player.moveRight == true)
{
if (%this.getAnimationName() $= "playerRunAnimation")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(PlayerRunAnimation);
return;
}
}else
{
%this.playAnimation(PlayerRunAnimation);
}
}else
{
%this.playAnimation(PlayerStandAnimation);
}
}
Can anyone help me understand what's going on?
07/16/2008 (11:38 am)
Here's my playerClass.csfunction playerClass::onLevelLoaded(%this, %scenegraph)
{
$player = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%this.enableUpdateCallback();
}
function playerLeft()
{
$player.moveLeft = true;
}
function playerLeftStop()
{
$player.moveLeft = false;
}
function playerRight()
{
$player.moveRight = true;
}
function playerRightStop()
{
$player.moveRight = false;
}
function playerJump()
{
if(!$player.airborne)
{
$player.setLinearVelocityY(-150);
$player.airborne = true;
}
}
function playerClass::updateHorizontal(%this)
{
if (%this.moveLeft && %this.moveRight)
{
%this.setLinearVelocityX(0);
return;
}
if (%this.moveLeft)
{
if (!%this.againstLeftWall)
{
%this.againstRightWall = false;
%this.setLinearVelocityX(-30);
}
return;
}
if (%this.moveRight)
{
if (!%this.againstRightWall)
{
%this.againstLeftWall = false;
%this.setLinearVelocityX(30);
}
return;
}
if (!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
}
function playerClass::updateVertical(%this)
{
%yVelocity = %this.getLinearVelocityY();
%this.setLinearVelocityY(10);
%collision = %this.castCollision(0.005);
%normalX = getWord(%collision, 4);
%normalY = getWord(%collision, 5);
// no collision
if (%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
%this.setLinearVelocityY(%yVelocity);
return;
}
// collides with wall to the left
if (%normalX == 1 && %normalY == 0)
{
%this.againstLeftWall = true;
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// collides with wall to the right
if (%normalX == -1 && %normalY == 0)
{
%this.againstRightWall = true;
%this.setLinearVelocityX(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// on ground with no wall collisions
if (%normalX == 0 && %normalY == -1)
{
%this.airborne = false;
%this.againstLeftWall = false;
%this.againstRightWall = false;
%this.setConstantForceY(0);
%this.setLinearVelocityY(%yVelocity);
return;
}
// in air and hits platform with head
if (%normalY == 1)
{
%this.airborne = true;
%this.setLinearVelocityX(0);
%this.setConstantForceY(100);
%this.setLinearVelocityY(%yVelocity);
return;
}
// in case another type of collision normal was detected
error("another collison type" SPC %normalX SPC %normalY);
%this.airborne = false;
%this.againstLeftWall = false;
%this.againstRightWall = false;
%this.setLinearVelocityY(%yVelocity);
}
function playerClass::onUpdate(%this)
{
%this.updateHorizontal();
%this.updateVertical();
%this.setCurrentAnimation();
}
function playerClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
%yVelocity = %this.getLinearVelocityY();
if (%xVelocity > 0)
{
%this.setFlip(false, false);
}
else if (%xVelocity < 0)
{
%this.setFlip(true, false);
}
if (%this.airborne)
{
if(%yVelocity < 0)
{
%this.playAnimation(PlayerJumpUpAnimation);
return;
}else
{
%this.playAnimation(PlayerJumpDownAnimation);
return;
}
}
if ($player.moveLeft == true || $player.moveRight == true)
{
if (%this.getAnimationName() $= "playerRunAnimation")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(PlayerRunAnimation);
return;
}
}else
{
%this.playAnimation(PlayerRunAnimation);
}
}else
{
%this.playAnimation(PlayerStandAnimation);
}
}
Can anyone help me understand what's going on?
Associate Phillip O'Shea
Violent Tulip
If the value is negative, then the player will go UP.