How to apply a force at certain point of an object?
Hello everybody,
I'm currently working on a physics based game and I'm wondering, how you can add force at a specific point of an object, so that it's being physically-influenced based on the position you click at.
A good example for that would be "Clumsy Ninja", where the Ninja's head snaps back when you tap it, the legs are being pushed away when you tap them, etc., except for the fact that I am working with a solid object, a Cube, for example.
void FixedUpdate() { if (Input.GetMouseButtonDown (0)) { Vector3 position = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, distance); position = Camera.main.ScreenToWorldPoint (position); GameObject bullet = Instantiate (forceBullet, transform.position, Quaternion.identity); bullet.transform.LookAt (position); bullet.GetComponent<Rigidbody> ().AddForce (bullet.transform.forward * force); } }
What you see up there is what I am currently working with. I am Instantiating bullet-like objects which then travel to the point I clicked at, literally pushing the object, but I am certain that there is a more efficient and better-working way to handle that, as the "bullet-thing" is far from perfect!
Many thanks in advance!
Your answer
Follow this Question
Related Questions
How to fix this problem? 1 Answer
Problem. Pick up and Grab object script, except all objects in scene are picked up instead of one. 0 Answers
How do I get objects in front of the player to be blasted away? 1 Answer
Ball Speed is not increasing as per code 0 Answers
Getting two Objects to the same direction with different speed 0 Answers