Attaching a gameObject above a rolling ball
I would like to have a rolling ball as the base of my player movement but then a body that sort of sits above it. Like bb8s head from Star Wars.
Everything Ive tried results in the object rolling with the ball or becoming detached. I cant find anything online and would appreciate any help.
EDIT: Well I managed to find a solution before this post was even moderated but incase anyone else is wondering the solution is very simple.
Create an empty game object as a child of your sphere(ball). Reset its transform in the inspector so it should be dead centre, now make sure to separate it so it is no longer a child of the player. Attach a script to the gameObject making it follow the sphere.
Heres mine:
public Transform followSphere;
void Update () {
transform.position = followSphere.transform.position;
}
Then attach your player as the followSphere target in the inspector. Create the head/body of your player(Like bb8s) and child it to the empty gameObject. Offset it by the spheres radius and you're done.
Answer by Ran-Quan · Mar 22, 2017 at 04:53 AM
Setup your player like this:
ObjectRoot is your player's root object, it won't rotate at all. Change its position if you want to move your player.
StableHead is your player's head, it's attached to the root so it won't rotate too.
RollingBall is your player's rolling body, change its localRotation if you want it to rotate. It's attached to the root so it's transform won't affect either its parent or its sibling StableHead.
That would work fine however my method is based around movement from the ball. What I mean is since ObjectRoot is the parent, if you left your ball on say a slope it wouldn't move until you ran the script to move the ObjectRoot whereas $$anonymous$$e would roll unless the break key is pressed.
Thanks for answering though people can use either option depending on the gameplay they're going for :)