- Home /
Aiming Direction of Player altered After collision
Hello! I've been working on a top down shooter game recently and I've run into a weird issue. So I used a vector2 variable to calculate the direction my character should look at (mouse position - rigidbody2d.position), and everything works fine until my character collides with something. After the collision, there's an offset between my mouse position and where my character looks at and shoot, as illustrated by the images below. I'm suspecting that it has something to do with rigidbody but I'm not sure how to solve it. Any help is greatly appreciated!
Answer by gimmethatmod · Jun 03, 2021 at 06:03 PM
I have been having this problem for a long while now, but finally found the answer and its quite simple. for the players rigidbody just freeze rotation on the z axis under the Constraints tab. This doesnt freeze the rotation of the gameobject itself. so as long as you are not controlling your characters rotation using the rigidbody and instead you are controlling the rotation using the actual gameobjects transform rotation (which you should) then it will fix your problem!
Your answer
Follow this Question
Related Questions
2d top-down rpg direction check 1 Answer
I am having problems with making my character face the movement direction after stopping. 1 Answer
How can I increase or decrease jump speed while keeping the jump arc the same? 1 Answer
trouble setting map boundaries of top down 2d shooter 1 Answer
add force on topdown bullet 1 Answer