|
Hello, can anyone help me, please? I'm making an old school platform game with a movement in 2 dimensions. Everything works quite well except one thing. Every time my character jumps into the wall it's stuck in there until a key for horizontal movement is released. Is there a way how to fix this? Thanks in advance.
(comments are locked)
|
|
a typical approach is, just add a line of code that stops all input, for say, a second after you bash in to something. in other words once you hit something, allow the physics engine to fling you around for a little bit, before there is any more input. Hope it helps! Thank you. I'm still a newbie, could you please tell me how to transform this logic to a code in javascript? I already made the flinging code but I don't know how to stop all input.
Jun 07 '12 at 10:52 AM
zeal
(comments are locked)
|
|
(Answer to your comment on Fattie's answer) Just create a variable and say that they can only use the input if that variable is true. Make it turn false whenever it hits something: Btw be careful with the "else" statements and remember that they're there. Noob-E: Thanks! This looks good. I'm still struggling with Unity javascript, but I think I will learn it one day.
Jun 09 '12 at 02:15 AM
zeal
(comments are locked)
|

We gonna need more information on how you make your character moves, maybe a bit of code too.
public function Update () : void { if (Input.GetButton("Horizontal")) {
in_direction = Input.GetAxis("Horizontal") < 0 ? -1: 1; rigidbody.velocity = new Vector3((in_direction*f_speed), rigidbody.velocity.y, 0);
if (!b_isJumping) { if (Input.GetButton("Horizontal")) {
in_direction = Input.GetAxis("Horizontal") < 0 ? -1 : 1; rigidbody.velocity = new Vector3((in_direction*f_speed), rigidbody.velocity.y, 0); loopSprites[0].resetFrame(); loopSprites[1].updateAnimation(in_direction, renderer.material); } else { loopSprites[1].resetFrame(); loopSprites[0].updateAnimation(in_direction, renderer.material); } if (Input.GetButton("Jump")) { //Jump b_isJumping = true;
loopSprites[0].resetFrame(); loopSprites[1].resetFrame(); rigidbody.velocity = new Vector3(rigidbody.velocity.x, -Physics.gravity.y, 0); } } else {
jumpSprite.updateJumpAnimation(in_direction, rigidbody.velocity.y, renderer.material); } }
The character just stays glued to the wall when a horizontal button is pressed. Any idea, how to fix it, please?