Rotate Sphere?
Hi
I'm looking for a way to have my player character (a Sphere gameobject) rotate both vertically and horizontally, yet have a gameobject attached to the player object that points in the same direction the player character is rolling but doesn't rotate...
I have the player sphere object rotating as I want it but I can't seem to get the additional gameobject to NOT rotate.
I've tried googling this and so far have come up with attaching a script to the 'non-rotating' gameobject with :
private Quaternion rotation;
void LateUpdate()
{
transform.rotation = rotation;
}
This allows the gameobject to follow the player sphere but doesn't point in the direction the sphere is rolling, additionally it sort of bobs about a bit.
Anyone have a suggestion how to solve this or could point me in the right direction?
Thanks
Answer by Asgardr · Jul 03, 2016 at 02:33 PM
Here's how I'd do it:
Have a root object with a player script attached. This does not have a model. It simply points in a direction, and moves in that direction when pressing forwards. It doesn't rotate! If you press left, it rotates left. If you press right, it rotates right.
Have a model object as a child to the root object. This has a separate script that listens to the same input. If you're moving forward, have the model roll forwards.
Have a pointer object as a child to the root object. This will always automatically point in the right direction. No script needed
I hope this makes sense. Try to figure it out, and if you can't make any sense of it, I'll create a small example for you.