Hello.
So, I’m building a game scene inside a sphere, normals reversed, material on the inside, et cetera. The character (using either the Starter Kit first or third person controller) will wander around on the inner face of that sphere.
How can I orient the character such that its UP direction always points to the origin (0,0,0), and all movement is relative to that orientation?
I’ve searched for over a week and have found no useable solutions. Any ideas would be most welcome.
Cheers.
Update: I put a sphere with no collider in the center (0,0,0), transparent, to use as an object of orientation. Still not right.
Update: It seems to me the answer is to set an object at 0,0,0 and apply gravity to that object, but reverse that gravity. However, every way I have attempted to do that has not worked.
Any ideas? Any example code I might check out?
Well, here for another shot at it. I could not find any useful answer on this forum or any other. Does anyone know how I might orient the characters such that their “up” is always towards a fixed point?
In order to set the upwards direction the way you want you need to find a vector that always points towards your target (e.g. Transform).
public Transform Target;
void OrientCharacter(Transform character)
{
// Get the target upwards direction
Vector3 up = Vector3.Normalize(Target.position - character.position);
// Set the up property direction
character.up = up;
}
Setting “up” will rotate the object for you. In fact, this is what that does:
//
// Summary:
// The green axis of the transform in world space.
public Vector3 up
{
get
{
return rotation * Vector3.up;
}
set
{
rotation = Quaternion.FromToRotation(Vector3.up, value); // <-------------
}
}
Another thing you can do is applying interpolation via the Slerp function:
public Transform Target;
void OrientCharacter(Transform character)
{
// Get the target upwards direction
Vector3 up = Vector3.Normalize(Target.position - character.position);
// Get how much rotation is required
Quaternion delta = Quaternion.FromToRotation(character.up, up);
// Apply only what you want (interpolation)
float t = 20f * Time.deltaTime;
character.rotation = Quaternion.Slerp(Quaternion.identity, delta, t);
}
Keep in mind that Unity’s CharacterController component (part of the starter kit, i think) does support only up = Vector3.up… or at least it was like this in the past.
Many thanks, lightbug14. I now have a starting point for trying to figure things out. 