I have a gameobject, a dog, that will go up to an object and is then supposed to pull the object back towards the player. Right now the dog is always moving forward, turning around after picking up an item, so its head is always facing the direction that it is going. I want to make is so when the dog is dragging an item it is moving butt first, navigating towards my player.
I have the model of the dog set as a child of an empty gameobject which is what has the NavMeshAgent. I’m unsure of how I would spin the dog in a way that makes it look like he isn’t spinning but instead standing still. Is there a good way to do this?
Or is it possible to just navigat backwards? I tried looking for backwards navigation but couldn’t find anything useful
I would build the object in an empty gameobject, so the navigating agent and the model itself are independent. Then when the agent must navigate backwards, I would just turn around the mesh and play the appropriate animations when needed. So the agent would navigate forward but since the mesh is in the other way it would appear that the dog is going backwards.
That is more or less what I already have set up. The problen is I don’t know how to rotate the dog model while the empty gameobject is rotating to make it look like the dog model isn’t rotating at all. Since I want it to look like the dog is walking up to the item then pulling it backwards, I don’t players to see the spinning of the navmeshagent
I tried rotating the entire dog game model when it reaches an item, which works fine. I can spin the whole game object 180 degrees. Now I want to turn just the model (a child of the dog empty game object) 180 degrees back but it doesn’t really work. It keeps rotating on the z axis even though I clearly have it set to the y axis. I am hoping if I spin the entire gameobject 180, then spin the model back 180 the gameobject will navigate forward but it will look like it is moving backwards. Here’s the code I have so far:
So when I grab the part, it should spin the object (which it does) then spin the model (which does wrongly). Same when it drops the part off. Any ideas?
Are you changing the animation to a “walk backwards” animation with root motion?
I don’t understand why you need to rotate it yourself.
The NavMeshAgent should rotate it for you, I understand this could look weird if you have a slow rotation speed.
When you change from walk forward to walk backward it would transition and spin around - you could fix that by making the transition in the animator instant.
Now you could also make the rotation speed of the NavMeshagent really high via code and let that handle the rotation for you.
Or you could use a script to rotate the dog yourself like in this thread, but set the rotation to the lookrotation once rather than lerping:
You’d also need to make sure your set the NavMeshAgent destination at the same time the dog picks up the object.
Hope something there helps…interesting problem… good luck!
Yeah its a bit of a unique problem, I guess I should be happy about that? Haha
So right now I am rotating everything instantly within 1 frame. As far as I can tell you can’t eve see the switch being made (I can’t see it at least). The main problem is that if I do no rotation of any kind and just rely on the navmeshagent, the dog will navigate to the item, pick it up, then walk back to the player facing forward (since the navmeshagent will always move in one direction). So the navigation all works just fine, but if I want the dog to look like he is dragging then I have to rotate him to move butt first. Hence the rotate of the gameobject then rotating the model back. It seems to work.
I actually haven’t done any animations yet for the dog, I figure I’ll get to that later when I need it.
@Corva-Nocta If you are planning on doing animations, now would be a good time, even if it’s a super simple animation.
You can get the dog to face backwards (butt-first) in the animation, but have the root pointing forward still.
Its butt will be facing forward and you wont need to make it walk backwards because the animation will handle that for you…
If you’ve got it working though, thats great
And yes, unique problems are good, it could mean you’ve got a unique game mechanic!
That is an interedting idea, having the model just reversed in the animation rather than having the gameobject in reverse. I would still need to spin the gameobject, but the child dog model’s animation could just have it be butt first. I may have to look into that when I apply a real model, it actually sounds like a simpler solution. Thanks for the advice!