- Home /
Controls help please!
In unity, I made a project and I added in a sphere. My input settings are set to the defaults (up and down keys and w and s keys for forward and backward, left and right keys and a and d keys for left and right) and I added in a sphere to the game. I played the game and I tried all 8 keys but my sphere wouldn't drop to the plane or move forward, backward, left, or right. I have a sphere collider on it and a character controller but it still wouldn't work.
Can somebody please tell me what I'm doing wrong?
Answer by aldonaletto · Aug 12, 2011 at 08:01 PM
You need to write a script to do the job, and drag this script to the sphere. A good example is given in Move - it includes gravity and jump (spacebar). The example script is:
var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
^ This is the correct answer ^ but since it sounds like you're fairly new to unity, remember to attatch this script to your game object for it to work, forgive me if that was already obvious.
Your answer
Follow this Question
Related Questions
How do i move around in the editor without using arrow keys or middle click. 1 Answer
How to add controls? (WASD) 1 Answer
3D Joystick hide / show on toggle save through scene 0 Answers
How do I create WASD controls for a fps? 3 Answers
Unity Editor RMB + WASD FPS flyby controls not working 1 Answer