Hi, bit of a n00b to Unity, I'm trying to get get a character model to ride on top of a horse. Rather than parent him in the hierarchy I want him to follow the horse using a script, as he will dismount it on occasion. I thought I'd worked out a really simple way of doing this using the following:
... where the target is a particular joint on the horse. Unfortunately, although this works, when the horse starts to move or turn quickly I notice that the character attached starts to gitter. Is there a better way to go about this?
asked Jan 17 '11 at 03:27 PM
Then set up Ride and Dismount keys in the Input Manager. There's no good reason not to use the parenting functions... it's the easiest and simplest way to do this. If necessary, put an empty object on the horse where you want the rider to sit, and parent it there (so you don't have to play around with the right offsets on your localPosition). But use parenting!
answered Jan 17 '11 at 03:47 PM
Assuming that your horse is being moved in Update() the problem might be that you are trying to move both rider and horse at the same time. Try moving the code that updates the rider when he is mounted into LateUpdate(). That way, each cycle the horse will first move to new position and then the rider will move to match after.
answered Feb 13 '11 at 07:16 PM
As Lambda Red says, it is undefined in which order a Unity-event is called on components. I do however not agree that LateUpdate() is your answer.
Why not? Update() +LateUpdate() can ONLY solve event ordering problems for pairs of objects, but NOT if you have 3 or more components that are dependent on each others.
what then? You have to make a system yourself. Here are some possible approaches:
1) Update the chain of dependent components at once. In your case just update the rider WHENEVER the horse has been updated. Yes, the horse can just call the rider explicitly. Con: You can get multiple update calls on your rider, if it depends on other objects e.g. the camera.
2) Explicitly control the event ordering yourself Only have a single game object with a component that implements the unity events e.g. Update() and lets this event central be THE ONLY ONE that distributes unity events to other components. The other components just register themselves on THE ONLY ONE with an event priority value. To check that some in the team do not make components that implement unity events, you can use reflection to check that only THE ONLY ONE declares unity events. Run this check when the game starts.
answered Feb 19 '11 at 11:40 PM