- Home /
Wall Jump and loops
Ok two questions,
Is there any while loops, or something similar, so i can do certain things while in a specific state? For example for the wall jump i want to say
// while(touching wall) { Pause for a second then drift slowly down }
otherwise gravity is normal //
But anything I try the character will drift slowly down after touching the wall then moving to the side and not actually being on the wall.
Second question. If i want him to jump off the wall, if there a better way then changing the horizontal velocity? I only want him to move about 5-10 'units' away from the way then hold normal horizontal velocity.
Answer by testure · Jun 21, 2011 at 05:11 AM
for your first question, you want to use a coroutine.
for your second question, you want to interpolate from one position to the other using Mathf.SmoothDamp.
mathf.smoothdamp looks goood, but I cant seem to figure out how to make it work. Does that just keep returning a value that i set to his x position?
I suppose my greatest question is how does Mathf.SmoothDamp work? I looked it up but cant figure it out http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothDamp.html
don't post questions or comments as answers. use the 'add new comment button'. It screws up the ordering of posts, and it doesn't read linearly. not to mention it messes up search results.
SmoothDamp eases one value to another at a specified speed. It requires a reference to a velocity variable so in order to make it happen. There's not really more to tell, that's all it does.
Answer by Dreamblur · Jun 21, 2011 at 05:25 AM
Either store your states in an Enum type variable or assign a toggle variable for each state.
You can clamp the horizontal component of the velocity after a specified condition is fulfilled.
Answer by CC_1759 · Apr 01, 2021 at 09:00 PM
@jlimbach i just used an if statement...` if (CheckIfOnWallToRight() == true) { // make you jump of the wall if ((Input.GetButtonDown("Jump")) && (Input.GetButton("d"))) { playerController.GetComponent().enabled = false; rb.velocity = new Vector2(-5, 10); wallJumpedFromRight = true; } // makes you wall slide else if ((Input.GetKey("d")) && (wallJumpedFromRight == false)) { rb.velocity = new Vector2(0, -1); Debug.Log(wallJumpedFromRight); } }
if (wallJumpedFromRight == true)
{
iR += 1;
}
if (iR >= 25)
{
iR = 0;
wallJumpedFromRight = false;
playerController.GetComponent<PlayerMovement>().enabled = true;
}`
Your answer
![](https://koobas.hobune.stream/wayback/20220612113352im_/https://answers.unity.com/themes/thub/images/avi.jpg)