- Home /
Make object face center of circle without flipping in 2D space.
Simple concept:
I have a sling in a 2D game.
The cup of the sling is a game object.
When pulled back, the cup of the sling should always face towards a center point, just like the cup of a real sling would when under tension.
Seems simple, but I have not been able to find a solution.
Things that did not work -
Using lookat does not work because the cup will flip halfway around the circle.
This solution:
var relativePos = center.transform.position - cup.transform.position;
var rotation = Quaternion.LookRotation(relativePos,cup.transform.up);
cup.transform.rotation = rotation;
almost works at the edges, but introduces rotation around y and z axes anywhere near the center. (this is a 2d game, so any rotation along those axes is no good)
Clamping those axes seems to break the solution as a whole.
This solution, found in another answer:
Vector3 oldV = targetPos-oldPos, newV = targetPos-curPos;
Quaternion changeRot = Quaternion.LookRotation(oldV, newV);
// the order of *'s matters, can never remember which one:
transform.rotation = changeRot * transform.rotation;
seems to just result in wild spinning.
edit: Sorry for not being able to get the code window to look right. It is not for lack of trying.
Your answer
Follow this Question
Related Questions
Player to always face 'track' forward direction 1 Answer
2D rotation question 0 Answers
Camera rotate around sphere centre 2 Answers
Rotate Z-Axis towards center. 0 Answers