Question by
Torchlit · Jun 27, 2016 at 12:25 AM ·
rigidbody2dcollisions
Prevent Player from Rotating Into Wall
Hello!
I'm making a game where the player is able to rotate based on the direction their velocity is going.
The player can move around using the regular WASD controls.
I've found that this creates some issues whenever the player rotates into some of the barriers I placed on the edges of the screen.
Here is a video demonstrating the issue.
Here is the code that controls the direction of the player:
void FixedUpdate() {
//Calculating the angle
float angle = Mathf.Atan2 (thisRigidBody.velocity.y, thisRigidBody.velocity.x) * Mathf.Rad2Deg;
//Setting the rotation
thisRigidBody.MoveRotation (angle);
}
The player has a 2D RigidBody, a 2D Polygon Collider and a script for controlling movement and the rotation.
What I want to happen is for the player to hit the wall and lay against it, as if the force were like an angular force set on the RigidBody.
Any help would be appreciated. Thank you!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612083732im_/https://answers.unity.com/themes/thub/images/avi.jpg)