There suppose to be no collision
by Danny Koo · in Torque Game Builder · 09/21/2005 (10:04 pm) · 5 replies
I binded the up arrow key with doJump() on key and doJumpStop() off key. I have player setup and floor tilemap setup, each of them tagged respectively.
So I have this problem. Whenever I tapped the up arrow key once, I get:
player jumping
player touch ground!
This happens even way before player touches the ground!!! That means doStandingAnimation() kicked in even before I collided with the ground.
However, if I double tapped the jump key, I jump twice and the animation is perfect, it will not execute doStandingAnimation until it collide with the ground. However, it should not jump twice unless $isJumping is set to false which means the first tap trigger a collision even though it is not colliding. Anyone knows what I'm talking about? Any suggestion will be great!
$touchGround=true;
function doJump()
{
if($isJumping==false)
{
echo("player jumping");
$isJumping=true;
$touchGround=false;
$player.setImpulseForce("0 -400", 1);
jumpAnimation();
}
}
function doJumpStop()
{
if($touchGround==true)
{
echo("player touch ground!");
doStandingAnimation();
$isJumping=false;
}
else
schedule(1000, 0, doJumpStop);
}
function fxSceneObject2D::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(%srcObject.tag$="player"&&%dstObject.tag$="floor")
$touchGround=true;
}So I have this problem. Whenever I tapped the up arrow key once, I get:
player jumping
player touch ground!
This happens even way before player touches the ground!!! That means doStandingAnimation() kicked in even before I collided with the ground.
However, if I double tapped the jump key, I jump twice and the animation is perfect, it will not execute doStandingAnimation until it collide with the ground. However, it should not jump twice unless $isJumping is set to false which means the first tap trigger a collision even though it is not colliding. Anyone knows what I'm talking about? Any suggestion will be great!
#2
09/22/2005 (4:03 am)
When you binded doJumpStop() to the off key, that means it will be called immediately after you let go of the up arrow. So if you are "tapping" the arrow quickly, then both the doJump() and doJumpStop() functions will be called very close to each other, regardless if your character is touching the ground or not.
#3
Sounds reasonable to me. Let me investigate this.
@Philip,
even if i tap quickly and execute both doJump() and doJumpStop() at the same time, doJumpStop can never be executed unless $touchGround is true.
09/22/2005 (7:55 am)
@teckSounds reasonable to me. Let me investigate this.
@Philip,
even if i tap quickly and execute both doJump() and doJumpStop() at the same time, doJumpStop can never be executed unless $touchGround is true.
#4
That did not solve the problem. Something is triggering the collision...
09/22/2005 (8:58 am)
@teckThat did not solve the problem. Something is triggering the collision...
#5
And, during the scene update, collisions are checked for before $player's position is updated, so you are still triggering the onCollision callback.
The way I handle jumping is to just set a global variable (like $playerJump) to true when the jump button is pressed, and false when it is released. Then, during your collision callback, you can do this:
The jump will only be triggered when $player is on the ground, because if it's not, the callback won't be triggered.
09/22/2005 (10:10 am)
Swapping the setImpulseForce call and the $touchGround = false doesn't work because setting the impulse force doesn't change the position of $player immedialetely. It merely changes its velocity so the position can be moved during the next scene update.And, during the scene update, collisions are checked for before $player's position is updated, so you are still triggering the onCollision callback.
The way I handle jumping is to just set a global variable (like $playerJump) to true when the jump button is pressed, and false when it is released. Then, during your collision callback, you can do this:
if(%srcObject.tag$="player"&&%dstObject.tag$="floor")
if ($playerJump)
$player.setImpulseForce("0 -400", 1);The jump will only be triggered when $player is on the ground, because if it's not, the callback won't be triggered.
Torque Owner Teck Lee Tan
$touchGround=false; $player.setImpulseForce("0 -400", 1);to$player.setImpulseForce("0 -400", 1); $touchGround=false;My guess:
What's happening is that you're setting the $touchGround flag to false before the player leaves the ground. On the next tick, onCollision is resetting the flag to true before the impulseForce gets applied. This would explain why doing a double jump fires the animation properly (the player is already in mid air when the second jump gets fired and therefore the flag doesn't get reset to true).