- Home /
Tree Fall Direction
Hey all. I am working on a game where you can select a number of trees a la RTS style, click a button, and select a spot where those trees fall but wondering how to make a tree object fall in a vector3 positions direction. Any thoughts?
Assu$$anonymous$$g that those trees are "static" at first, you'd probably would want to use them as rigidBodies when you want them to fall and add a bit of force into the direction you want them to fall in.
the problem is adding them in the direction of the click. it's a bit over my head.
I'm assu$$anonymous$$g that you want the trees to fall in the direction you clicked on the ground (and not on that exact point) so I would suggest to have a look at http://answers.unity3d.com/questions/346804/is-there-a-way-to-get-mouse-position-in-3d-space-a.html to get the 3D coordinates of where you clicked with the cursor (which returns a Vector3) and use that value with http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html to add force in that direction. I'm not too familiar with RigidBodies, so I'm assu$$anonymous$$g that this should be enough to get the trees falling (assu$$anonymous$$g that they won't start bouncing around the second you activate the rigidbody).
Or perhaps http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html ... try having a look at both and see if any of those work for you.
Answer by OP_toss · Sep 06, 2013 at 11:19 PM
You mean like this?
Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
tree.transform.rotation = Quaternion.LookRotation( ray.direction, Vector3.up );
This will make the tree's forward Z-axis point along your ray from the camera. I have no idea which direction you want, so if you wanna provide more info or fiddle with the above code, you should be able to figure it out :)
Hope this helps!
Only problem is... will this actually rotate the tree itself? I want it to fall in the direction of the click, not rotate. Think as if the tree decided to fall over in the direction of the click without any rotation at all.