x


Box collider in a platform game

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.

more ▼

asked Jun 07 '12 at 02:23 AM

zeal gravatar image

zeal
4 2 3

We gonna need more information on how you make your character moves, maybe a bit of code too.

Jun 07 '12 at 02:41 AM Berenger

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?

Jun 07 '12 at 10:46 AM zeal
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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!

more ▼

answered Jun 07 '12 at 09:26 AM

Fattie gravatar image

Fattie
18.9k 57 86 146

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)
10|3000 characters needed characters left

(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:

var canMove : boolean;

function Update(){
if(canMove){
//input code
}

if(hit){
canMove = false;
}else
canMove = true;

Btw be careful with the "else" statements and remember that they're there.

more ▼

answered Jun 08 '12 at 02:28 AM

Chimera3D gravatar image

Chimera3D
479 16 34 48

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)
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:

x49

asked: Jun 07 '12 at 02:23 AM

Seen: 464 times

Last Updated: Jun 09 '12 at 02:15 AM