- Home /
2D game movement/jump issue
Hi, im working on a 2d Platform game, moves and jumps fine, but if i jump and hit a wall for example and the movement key is still pressed, i.e. the object is colliding with the wall and key is still pressed, my object does (not) fall to the ground freely, it slowly drops down, unless i let go of that movement key...
I tried box, capsule colliders, as well as a character controller. And im not using force to move the player, just a simple transform translate function.
Any ideas why this is happening and how it can be fixed.
Thanx in advance cheers
I believe what is happening is the overall direction of the object when the movement key is pressed down is now diagonal rather than straight down (if that makes sense).
function Update () {
leftnright();
}
function leftnright () {
if(Input.Get$$anonymous$$ey("left")){
character.Translate (-speed * Time.deltaTime,0,0);
}
if(Input.Get$$anonymous$$ey("right")){
character.Translate (speed * Time.deltaTime,0,0)
}
}
Answer by robertbu · Jun 28, 2013 at 01:27 AM
My guess is that you are driving your character against a surface and the physics engine is preventing it from falling at full speed. Note you may want to consider using AddForce() or Rigidbody.velocity rather than Transform.Translate() to move your character if your character has a Rigidbody.
One potential solution to your problem would be to disable keys when you are in a collision. I don't know if that will work given your game play. I would create a boolean and set it true in OnCollisionStay(). After checking it in Update(), I'd set it to false. I'd do it this way rather than use OnCollisionEnter()/OnCollisionExit() since I've seen posts were OnCollisionExit() is not always called for every OnCollisionEnter().
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to add event to an object 1 Answer
Disabling the Z axis? 1 Answer
2D Game Movement script(W,A,S,D input only)? 1 Answer
2D Multi-Wheel Collider/wheel, detecting Wheel Hits 0 Answers