- Home /
The question is answered, right answer was accepted
Recoil on self-object
Simply enough I want a simplest script to get an idea on how the recoil works. What I mean by this is when I shoot the cannon on my boat, I want the boat itself to go back a bit.
Thanks :)
Answer by Minuks · Dec 10, 2017 at 02:10 AM
You could use AddRelativeForce(Vector3.forward * thrust, ForceMode.Impulse);
see documentation
Wasn't most clear answer, but I realised that it isn't hard to do at all anyways :)
Here's the code I used on the object
public GameObject boatBody;
int recoilForce;
Rigidbody boatRb;
private void Start()
{
recoilForce = 100000;
boatRb = boatBody.GetComponent<Rigidbody>();
}
void Function()
{
boatRb.AddRelativeForce(projSpawner.forward * -recoilForce);
}
}
Follow this Question
Related Questions
Why do I get: "Cannot cast from source type to destination type"? 1 Answer
How to access component that the raycast hit 1 Answer
How to delay time reset on collision? 2 Answers
Unexpected Force being applied after adding rigidbody 1 Answer
Accessing the rigidbody of a certain game object via script? 1 Answer