Hi, I'm having trouble with a player controller I'm developing. Basically, there are many small planetoids... the player can run around on these planets (so gravity is always a force that is planet.position - player.position)
(Unity C#)
I can move the player around the planet just fine, and the player's up vector always faces opposite gravity direction, but I can't seem to rotate the player towards horizontal input axis if the gravity is anything other than -y.
ie, if I change gravity like I am, planet.pos - player.pos, i can't seem to simultaneously affect both the up vector of the player and a rotation around that up vector
It appears I don't know how to affect a single quaternion axis... for example, I'd love to do something like...
rotate.yAxis(horizontal input * rotation speed) while local upVector = -gravityDirection
but unfortunately that's only pseudo code : (
here is code that's getting me close
void FixedUpdate()
{
_rigidbody.MovePosition(_rigidbody.position + transform.TransformDirection(moveDirection) * moveSpeed * Time.deltaTime);
gravityDirection = (_planetoid.transform.position - transform.position).normalized;
_rigidbody.AddForce (gravityDirection * gravityStrength);
gravityRotation = Quaternion.FromToRotation (Vector3.up, -gravityDirection);
OnTurn(gravityRotation);
}
void OnTurn(Quaternion rot)
{
targetRotation *= Quaternion.AngleAxis(rotationVelocity * h * Time.deltaTime, transform.up);
transform.rotation = rot; // ******** swap this out for targetRotation ***********
}
// ******** swap this out for targetRotation ***********
this is saying that if rot is the variable being used, the player runs around the player properly (always appearing to be standing upright no matter where they are on the planet), but rotating towards input doesn't work.
if you swap rot out for targetRotation, the player rotates towards input axis, but no longer aligns to the planets surface
any help would be amazing