- Home /
rotate the object based on the two-point
Hi friends, I want to return a specific object, but somehow I could not find by two points. I'd appreciate if you help, thank you :)
Do you want to rotate (as in the heading) or find&return an object (in your text below)?
Is this for a touchscreen, where the two points are two touches?
I'm a fake car physics
When the wheels up, according to him must return the red-colored boxes.
Not sure if this will help but if you want to implement car physics it's probably best to stick with the existing WheelCollider classes or take a look at this: http://wiki.unity3d.com/index.php/WheelColliderSource
Answer by kittenkong · Mar 13, 2013 at 09:46 AM
I struggled with this for ages and finally found a solution.
First move your object to the center point of the two points
transform.position = (p1 + p2)/2.0;
then align your object between the two points
transform.rotation = Quaternion.LookRotation(p1 - p2, Vector3.forward);
Thats it, too easy.
Sorry to resurrect this thread, but is it possible to use Joint ?
You can put a joint between 2 objects and adjust the settings, but it's difficult to tell a joint "now I want you to go to X degrees". They're best when you want something to move like a real-world connection, but don't care exactly how.
Answer by The-IT664 · Mar 01, 2013 at 04:07 AM
Seems like what you want to do is find the mid point between the two contact positions then rotate about the mid point.
You should be able to do this through transform parenting, though it's not entirely trivial.
Your answer
Follow this Question
Related Questions
Object facing the wrong way? 1 Answer
Making a rigidbody cube snap 90 deg at a time 1 Answer
Moving to an object i click. 1 Answer
Rotate Object to face 2 axis? 1 Answer