- Home /
Fixed Camera, Mouse aimer, How do I animate this?
Okay here's the deal, I've been going without sleep trying to work this out. Ive been using java script, but I will start using c# if that is what is needed.
I have a basic movement script on my Parent, to move on world axis. I have a child under that which my character model is on, which aims towards the mouse.
My problem is working out how to animate this player model based on the direction its facing, but also the movement the parent is doing.
Ive tried an animation script trying to use velocities, but my current hierarchy doesn't allow me to do this so easily. I think I have to start thinking of how to do this from a fresh start.
If anyone could point me in the right direction I'd be most grateful.
Is your child successfully ai$$anonymous$$g towards the mouse now? What problem are you seeing? I don't understand what you mean by "animate this player model based on the direction its facing, but also the movement the parent is doing".
Sorry I wasn't sure how to phrase this. $$anonymous$$y $$anonymous$$ouse aim is working fine, character faces towards the mouse, but my parent is moving in its own directions, I need to animate the based on how the parent is moving, but also which direction the character is pointing.
So you want the parent movement to be affected by the direction that the child character model is pointing? Is the problem that when you change the parent that it also affects the child making him have to turn towards the mouse again?
The movement is fine, character always stays aimed at mouse.
Is there a way I can read the world velocity of the parent and relay it back to the character model, but also tell which direction the character is facing and play animation based on that.
If your parent has a rigidbody, then just use rigidbody.velocity. If not, then you'll have to subtract two positions on separate frames and divide by Time.deltaTime. Once you have this velocity in global coords, you can convert it to local coords of your child by using:
localVelocity = child.transform.InverseTransformDirection(velocity)
This will be the velocity of the parent, but in the child's coordinate system (which takes into account the direction the child is facing). You can use this to decide which child animation to do.
Answer by iantlloyd · May 26, 2011 at 06:33 AM
I ended up setting up some triggers, and whatever trigger the character was pointing at it would swap the keys for the animation cycles. I don't think its very efficient, but it works for now.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084723im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I access the "Average Velocity" of a run animation? 1 Answer
Check if FPS Character Controller Is Moving Then Switch Animations 2 Answers
2D platformer composite collider animation bug 2 Answers
Velocity and Animator change while game is Paused 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers