Hello,
I got my ship sailing around a sphere just fine, but at certain points on the sphere the ship will go diagonal (usually after a collision) or it will refuse to go forward as if there was an invisible collider (there isn’t i checked).
I’d really like a sanity check and general feedback on my code so i can improve.
private void TurnShip()
{
//Rotation code to align with surface
Vector3 surfaceUp = transform.position - Vector3.zero;
Quaternion surfaceUpRotation = transform.rotation;
surfaceUpRotation.SetLookRotation(surfaceUp, -transform.forward);
surfaceUpRotation *= Quaternion.Euler(90,0,0);
transform.rotation = surfaceUpRotation;
//Turn controls
if( Input.GetKey( KeyCode.LeftArrow ) )
transform.Rotate(0, -1 * turnSpeed * 30 * Time.deltaTime, 0);
else if( Input.GetKey( KeyCode.RightArrow ) )
transform.Rotate(0, turnSpeed * 30 * Time.deltaTime, 0);
}
private void MoveShip()
{
Vector3 adjust = Vector3.zero;
//Check if we are touching the ground; move down if not
if( !Physics.Raycast( transform.position, -transform.up, 1f ) )
adjust += (transform.position - Vector3.zero).normalized * -2;
Vector3 moveDirection = new Vector3( 0, 0, 1 );
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
moveDirection.y -= 20 * Time.deltaTime * transform.up.y;
moveDirection += adjust;
cc.Move(moveDirection * Time.deltaTime);
}