- Home /
Limiting Wall Jump to only certain Object Collisions
So, I am using the wall jump function fromthe Lerpz tutorial for my new player controller script, however, the one from the lerpz tutorial allows walljumping on anything you collide with to the side. I want to limit the wall jumping to ony certian onbject only. From what I can see, this is what allows that:
// Store when we first touched a wall during this jump
if (collisionFlags == CollisionFlags.CollidedSides)
{
touchWallJumpTime = Time.time;
}
I want to only allow walljumping on objects in a particular layer (or tag) only so that the player can't walljump on any object. Here is the complete function:
function ApplyWallJump () { // We must actually jump against a wall for this to work if (!jumping) return;
//if (!letGo)
// return;
// Store when we first touched a wall during this jump
if (collisionFlags == CollisionFlags.CollidedSides)
{
touchWallJumpTime = Time.time;
}
// The user can trigger a wall jump by hitting the button shortly before or shortly after hitting the wall the first time.
var mayJump = lastJumpButtonTime > touchWallJumpTime - wallJumpTimeout && lastJumpButtonTime < touchWallJumpTime + wallJumpTimeout;
if (!mayJump)
return;
// Prevent jumping too fast after each other
if (lastJumpTime + jumpRepeatTime > Time.time)
return;
if (Mathf.Abs(wallJumpContactNormal.y) < 0.2)
{
wallJumpContactNormal.y = 0;
moveDirection = wallJumpContactNormal.normalized;
// Wall jump gives us at least trotspeed
moveSpeed = Mathf.Clamp(moveSpeed * 1.5, trotSpeed, runSpeed);
}
else
{
moveSpeed = 0;
}
verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
DidJump();
SendMessage("DidWallJump", null, SendMessageOptions.DontRequireReceiver);
Debug.Log("Stupid Wall!");
}
Answer by Jason B · Jan 31, 2011 at 08:58 PM
Okeydokey. Was that the question? :D What seems to be the problem? Your script looks good. Only thing it's lacking is a simple check to allow that whole chunk of wall jump code to take place.
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag = "AWallJumpableWall")
{
// Do wall jumpy things!
}
}
Straight from the manual, just slightly modified.
LOL, thanks, I'll try it out once I get home on my work computer! Yeah, I don't think I completely put my question in "question form"!
Your answer
Follow this Question
Related Questions
Why is my AI not thinking the collisions fast enough? 1 Answer
making bullets disappear when they collide 3 Answers
Performance: How expensive are Trigger Collisions? How many collision layers should be used? 1 Answer
[RESOLVED] Pressing the "Z" key to make him go through certain terrain objects? 1 Answer
How to setup a local multiplayer game? 0 Answers