hey guys
i have an issue with rotations and quaternions, and i don’t even know what to search for.
i have this setup:
- no gravity in unity
- sphere trigger, giving constant negative force to the fireball
- fireball in the trigger with the script below on it.
- z-position reset of the fireball in late update to achieve 2d gameplay.
this is what is happening at the very top and the very bottom of the circle:
the y direction is changing suddenly. i tried it with “LookAt” and the now in use “LookRotation”.
does anyone know what i can do so the y direction doesn’t suddenly switch? i hacked in a hacky solution, but that also turns the model attached to the rigidbody around, and that looks very stupid ![]()
script:
function FixedUpdate() {
if(initialSpeed != 0) {
var relativePos = magneticAsteroid.transform.position - transform.position;
var rot : Quaternion = Quaternion.LookRotation(relativePos);
transform.rotation = rot;
//dirty hack so the orbiting is working...
if(transform.rotation.y <= 0) {
rigidbody.AddRelativeForce(0,-7,0);
}
if(transform.rotation.y >= 0) {
rigidbody.AddRelativeForce(0,7,0);
}
}
}
function LateUpdate() {
if(moveInProgress) {
gameObject.transform.position.z = 0;
}
}