Question by
Signalised · Apr 23, 2020 at 09:25 AM ·
scripting problemphysicsrigidbodyrigidbody2dphysics2d
Adding force to a rigidbody opposite to the direction of a rotating weapon
Hello! its my first time using Unity Ask, for please forgive any mistakes
I have a character who has a weapon which rotates towards to the mouse position, the code for this is below
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
if (rotZ > 90 || rotZ < -90)
{
//Flips Weapon if we point in the opposite direction
if (player.transform.eulerAngles.y == 0)
{
transform.localRotation = Quaternion.Euler(180, -0, -rotZ);
}
else if (player.transform.eulerAngles.y == 180)
{
transform.localRotation = Quaternion.Euler(180, 180, -rotZ);
}
}
I want to be able to get the current rotation of the weapon, and add a force opposite to the rotation, something like Scout Jumping from TF2 link : https://www.youtube.com/watch?v=0hdXTMgahFo ( Around 1:12)
would appreciate if u help me
Comment
Your answer
Follow this Question
Related Questions
RigidBody becomes awake without a collision 1 Answer
Collision sticking? 1 Answer
Rigidbody rotate velocity 0 Answers
How to change rigidbody type correctly? Angry Birds Game 1 Answer