- Home /
Adding force at an angle 2D,Adding force at an angle
I've been trying to learn how 2D physics work. My goal for this project is to get my character to move opposite to the direction he fires his gun in, while it does at force it does it in an odd way. Instead of the character continuing to move, instead he seems to just stop and go up while in the air. I have posted a video below and a picture of the code I am using to calculate the force added. Link to video: https://youtu.be/O68TcH2QkFU
Any help is appreciated, thank you!
Answer by lgarczyn · Nov 04, 2019 at 07:40 PM
First, you do not need to (and really shouldn't) use trigonometry here. Functions such as Quaternion.LookAt are usually enough. Functions such as Quaternion.Euler should be avoided, in favor of multiple AngleAxis, though that's not a problem here.
Second, I would suggest using a ForceMode.Impulse for AddForce, which has the advantage of taking the mass of the player into account, and not dividing the force by the framerate.
Third, it appears that your character controller script is simply reducing your lateral velocity to 0 when there are no inputs. You can probably reduce or temporarily deactivate this effect.