- Home /
Script problem
Hey! I'm new to unity, so why does this script not work. I've asked this question already but the question died, so I'm posting it again with more details.
var speed = 7.0; var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);
if (Input.GetButtonDown("Jump"));rigidbody.AddForce (Vector3.up * 200);
} ;
The movement part works, but jumping doesn't. No errors, it just doesn't add speed to the character gameobject I want the script to add force to my game object, so that it acts like a bird, you know when spacebar is tapped, the character flaps its wings and like... And yes, I have a rigidbody and no, it's not set to kinematic. Please help! Thanks.
Answer by GerryM · Feb 09, 2013 at 02:43 PM
Don't place ";" after your if statement in line 10:
if (Input.GetButtonDown("Jump")) rigidbody.AddForce (Vector3.up * 200);
Yeah, thanks, that's indeed A problem but it's not THE problem... $$anonymous$$y object is still not flying :P Thanks though!
You should not mix Rigidbody and the CharacterController components. The latter is there to make your character physics easier.
Answer by WelRC · Feb 09, 2013 at 03:54 PM
Try Input.GetButton("Jump"), because GetButtonDown("Jump") only returns true on the frame that button started to be held down. If the player keeps holding it down, it won't return true.