I'm trying to add force to my rigidbody from the direction it is hit by raycast.
Please help, here's my code: if (Input.GetButtonDown("Fire1")) { Kick(250); } void Kick(float kickStrength) { RaycastHit hit; if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, 2)) { if (hit.rigidbody != null) { hit.rigidbody.AddForceAtPosition(playerCamera.transform.forward * kickStrength, hit.point, ForceMode.Impulse); } } }
Your answer
Follow this Question
Related Questions
Animator consecutive set parameter problem 0 Answers
Reflection NullReferenceException: Object reference not set to an instance of an object 2 Answers
How can i look for collisions of the bulidngs in may array ? how can i use OnTRiggerEnter/exit ? 0 Answers
Why am I getting a Null Reference Exception? 0 Answers
Accessing a non-static string variable in another script C# 1 Answer