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
hero.position = saddle.position;
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-
function Update(){
transform.rotation.z = 0;
var rider= GameObject.Find("Player").transform;
var saddle = GameObject.Find("saddle").transform;
var heros = GameObject.Find("Player");
rider.position = saddle.position;
rider.rotation = saddle.rotation;
var controller : CharacterController = GetComponent(CharacterController);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
controller.SimpleMove(forward* curSpeed);
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
animation.CrossFade("walk");
}else{
animation.CrossFade("idle");
speed = 7;
}
if (Input.GetButton ("Jump"))
if (controller.isGrounded) {
moveDirection.y=jumpSpeed;
animation.CrossFade("walk");
}if (Input.GetButton ("run")) {
speed = 20;
}if (speed >7){
animation.CrossFade("run");
}if (Input.GetButton("dismount")){
hero.riding = false;
heros.GetComponent(playercontrollscript).enabled =true;
GetComponent(cowboyscript).enabled = false;
GetComponent(followmescript).enabled = true;
}
}
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!