- Home /
Player forward in Kinect
Hi everyone!
Here's my problem. I suck at rotations, so I don't really know how I would rotate this. The thing is, I have three objects. One in the middle, the others on the sides. The ones on the sides move freely, but never rotate. They always look forward. The central object should rotate depending on how the others move. It should rotate so that it always has the other objects at its sides.
"Ok, yes, I also have a point for the head that I could use"
Thanks for reading! I hope you can help me!
Not clear! How should the middle object align to the others? Please post a drawing - even the most awful one is worth a thousand words!
It would be something like this: http://desmond.imageshack.us/Himg528/scaled.php?server=528&filename=rotation.png&res=landing
How could I make the $$anonymous$$pot rotate like that if I only have the positions of the balls?
Answer by whydoidoit · Sep 23, 2012 at 07:30 PM
Ok I haven't tried this but I think that it's right! The position in the centre of the line is calculated by:
var ball1Position = ball1.transform.position;
var ball2Position = ball2.transform.position;
var connectingLine = (ball2Position - ball1Position);
var centrePoint = ball1Position + (connectingLine * 0.5f);
Given that you now need to decide which way to point the centre object- this needs another vector to describe what would be up.
var upVector = Vector3.up; //Or use something else (like the head per @fattie)
Now rotate the line 90 degrees around that axis for the rotation of the object.
yourObject.rotation = Quaternion.LookRotation(Quaternion.AngleAxis(90, upVector) * connectingLine, upVector);
yourObject.position = centrePoint;
Hey there! $$anonymous$$aybe if I clarify what I'm trying to do, it'll help you understand what I need: I'm working on a $$anonymous$$inect project that's giving me certain "nodes". The one's I'm interested in are HIP_CENTER, HIP_LEFT and HIP_RIGHT that move around 3d space but don't rotate. So what I'm trying to do is rotate the hip's center so that it's left side is looking at HIP_LEFT and it's right side is looking at HIP_RIGHT. So if the player turns round, so does the hip's center. And if the player tilts his body left or right, the hip rotates too.
Because then your upVector is Vector3.Cross(ball1Position - hipCenterPosition, ball2Position - hipCenterPosition) - presu$$anonymous$$g that it is not expressly on the line between ball1 and ball2.
It should be in the exact center between HIP_LEFT and HIP_RIGHT
Ok so I have these variables:
public Transform left; //Left hip
public Transform right; //Right hip
public Transform up; //Head
and this code:
Vector3 leftPosition = left.transform.position;
Vector3 rightPosition = right.transform.position;
Vector3 connectingLine = (rightPosition - leftPosition);
Vector3 centrePoint = leftPosition + (connectingLine * 0.5f);
Vector3 upVector = up.position - centrePoint;
transform.rotation = Quaternion.LookRotation(Quaternion.AngleAxis(90, upVector) * connectingLine, upVector);
But it spins around like crazy.