- Home /
What's wrong with my script?
OK, I'm just a beginner, so don't expect me to know much about JavaScript. I'm trying to get this script to work, the movement already works, but the addForce part doesn't. I can play without errors but whenever I press spacebar, my character doesn't jump. I'm trying to do a bird-themed game, so whenever I add force to th object, it doesn't need to be on the ground. Thanks!
var speed = 7.0; var rotateSpeed = 3.0;
var flap;
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);
flap = (Input.GetButtonDown("Jump"));
rigidbody.AddForce (Vector3.up * 200);
} ;
Answer by Julien-Lynge · Jan 31, 2013 at 06:04 PM
You are adding force to the rigidbody every frame - there is no if statement in there. Are you sure your character has a rigidbody, and it isn't set to kinematic?
No, the character does have a rigidbody, and is not set to kinematic. But how would I state that I want to add force only when spacebar is tapped?
Your answer
Follow this Question
Related Questions
moving with rigidbody without acceleration 0 Answers
How do I add a jump function to my current script? 1 Answer
Player appears to teleport instead of adding force 2 Answers
Jumping to high 0 Answers
Use addForce to Jump 1 Answer