Question by
SoulMiner13 · Feb 17, 2017 at 01:25 AM ·
scripting problemplayer movementfloating
Player floating away upon start
I'm new to game development, and have only followed a brief tutorial on it before trying out my own idea. At the moment, I'm only trying to get a cube to rotate and jump on a plain, which seemed easy enough, I just copied most of the code from the tutorial I had used to build a similar game. This time, however, my player starts and continuously floats upwards upon pressing the play button, and I know it's a script error because this only occurs if the script is applied to the Player game object. Here's the script, any help is appreciated, thank you!
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 10;
var distToGround : float;
var rotation : float;
function Start () {
distToGround = GetComponent.<Collider>().bounds.extents.y;
}
function isGrounded () : boolean {
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}
function Update () {
rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isGrounded ());
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612111302im_/https://answers.unity.com/themes/thub/images/avi.jpg)