- Home /
Player's collider stuck with wall collider when move button pressed even not grounded..
I want the player to fall down as it is not grounded on the platform; however it sticks on the wall. Player sticks on every wall with collider in the scene until left arrow is released. I even tried to add frictionless physic2D material to walls and player but it didn't work. Can anyone help me with this issue?
function update(){
grounded = Physics2D.Linecast(_transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Platform"));
RaycastHit2D hit = Physics2D.Raycast(_transform.position, Vector2.right, 10 ,1 << 8);
if (hit.collider != null && !grounded) {
lockControls = true;
} else {
lockControls = false;
}
if (!lockControls) {
move = Input.GetAxis ("Horizontal");
Vector2 _currentPos = _transform.position;
_currentPos.x += (move * speed);
_transform.position = _currentPos;
// and jump code goes here.....
} else {
_rigidbody2D.velocity = Vector2.zero;
}
}
Answer by nordaj123 · Jul 06, 2016 at 02:26 PM
Try moving the player by adding force to the rigid body. It would look something like this:
if (Input.GetKey(KeyCode.RightArrow))
rigidBody.AddForce(transform.right * speed);
rigidBody.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
This method has always worked the best for me when moving characters. This is in c#, JavaScript should be very similar though.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Always Get Same Physics Collision Rebound Force 1 Answer
Unity's collision system VS designing my own basic collision system 0 Answers
How to make a cube move towards the direction its being pushed to in a straight line? 0 Answers
I'm following a tut - converting to 3d - and confuzzled by RigidBody2d - vector 3 0 Answers