Hey unity people-
I have my hero, and a deer she rides. Both have a character controller. To ride the deer, I've said in script to attach the hero's center to a 'saddle' (an empty game object) I placed inside the deer, when I press the correct button and am in range of the animals side. She is able to get on perfectly in the right position, but when I press my 'run' button (makes the speed go from 7 to 20), the script seems to forget that I put
in the update function... The player is still riding, but she doesn't stay ON the saddle. The deer jerks and shakes forward and acts jittery when walking and more when running. It also makes the game crash after a while.
The thing is, sometimes when I load unity she is able to ride the deer PERFECTLY.
I think it is because their character controllers are colliding so it makes the deer jittery when moving.
The way I set up the script is to turn off the player's controll script and the deer's 'follow the player script', and enable a second script attached to the deer for an all new controlling script for riding.
I can't turn off the player's character controller because I instantly get hundreds of errors. Many things rely on the player current whereabouts- BUT, is there some way to turn off either's controller OR stop the deer from shaking indefinitely?
I have also tried to reposition the deer's controller but it doesn't seem to matter if the controller is no where near the hero or deer when riding- the deer always jitters.
here is the basic script for controlling the animal when riding-
Also, I do want the deer's x axis to rotate up or down when riding over the terrain instead of always being straight to the world- how do I allow it to rotate?
AND the deer cannot jump at all when the player is riding it. I also think it is because of the players controller. I tried to turn off gravity for both of them, but it doesn't work.
Any help is very much appreciated!
There are a lot of questions in there, and I can't answer all of them, but I think it would help you if instead of setting the players transform equal to that of the saddle each update, you just set saddle to be the parent of the players transform. That is,
This should execute during the mounting event. Then, during dismount, we set the players transform to have no parent:
As far as the x rotation of the deer goes, what you want to look for is the normal vector of the ground you are standing on, which you want to be your "up" vector. As for how to execute that in code, I would start with looking at the code in the CharacterMotor.js script related to groundNormal. It uses
You could run the same calculations as that function and then set the rotation equal to looking along the velocity vector.
For the deer jumping, I got nothing, unless you want to completely restructure your approach so that you set the deer to be child of the rider, and change the riders controller attributes accordingly (speed, height from ground, etc). We wouldn't be controlling the deer directly anymore, but the player-deer combined object thing. This would make a lot of what I wrote previously fairly irrelevant, too.
answered Dec 20 '10 at 06:27 PM
You can use most of what Mickydtron said and I think that will all work, then to get jumping to work, I would guess it's not working because the deer collides with the player controller. You can use Physics.IgnoreCollision(); in your deer script. Would be something to the extent of
answered Dec 31 '11 at 11:01 PM