x


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!");
    }
more ▼

asked Jan 30 '11 at 06:11 AM

SirVictory gravatar image

SirVictory
1.7k 64 77 104

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 31 '11 at 08:58 PM

Jason B gravatar image

Jason B
1.7k 29 32 44

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"!

Jan 31 '11 at 09:34 PM SirVictory

Coolies. Glad to help.

Feb 01 '11 at 01:36 AM Jason B
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2487
x150
x137
x99
x3

asked: Jan 30 '11 at 06:11 AM

Seen: 1428 times

Last Updated: Jan 30 '11 at 06:11 AM