Marble Game jump problem.

When i jump my marble disappears, and a lot of errors pop up. Really need help.:frowning:

First - Add this script to a sphere.
Second - Change its mass to 0.1
Third - Play the game and press Space Bar.

var speed = 300.0; 
var gravity = -5; 
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;

 function FixedUpdate() { 
 rigidbody.AddForce (Vector3(0, gravity, 0)); 
  
 var cameraTransform = Camera.main.transform; 

   // Forward vector relative to the camera along the x-z plane    
   var forward = cameraTransform.TransformDirection(Vector3.forward); 
   forward.y = 0; 
   forward = forward.normalized; 

   // Right vector relative to the camera 
   // Always orthogonal to the forward vector 
   var right = Vector3(forward.z, 0, -forward.x); 

  
 if (Input.GetKey ("w")) { 
   rigidbody.AddForce(forward * speed * Time.deltaTime); 
   } 

if (Input.GetKey("s")) { 
   rigidbody.AddForce(forward * -speed * Time.deltaTime); 
   } 
    
if (Input.GetKey ("d")) { 
rigidbody.AddForce(right * speed * Time.deltaTime); 
} 

if (Input.GetKey ("a")) { 
rigidbody.AddForce(right * -speed * Time.deltaTime); 
 } 
 
 
 if (grounded)
    {
	
	var velocity = rigidbody.velocity;
	
	if (canJump  Input.GetButton("Jump"))
        {
            rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
        }
    }
 
 
   // We apply gravity manually for more tuning control
    rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
    
    grounded = false;
 
 
}

 
 
 function OnCollisionStay ()
{
    grounded = true;    
}


function CalculateJumpVerticalSpeed ()
{
    return Mathf.Sqrt(2 * jumpHeight * gravity);
}

What errors get returned?

There are way too many errors for me to write, so it would be much easier if you test it yourself. :wink:

So i changed AddForce to AddTorque for more of a realistic look but now it moves really slow. No matter what the speed is (1 or 1000) it still moves the same speed. Whats wrong ?
(I still have the jumping problem)

var speed = 300.0; 
var gravity = -5; 
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;


 function FixedUpdate() { 
 rigidbody.AddForce (Vector3(0, gravity, 0)); 
  
 var cameraTransform = Camera.main.transform; 

   // Forward vector relative to the camera along the x-z plane    
   var forward = cameraTransform.TransformDirection(Vector3.forward); 
   forward.y = 0; 
   forward = forward.normalized; 

   // Right vector relative to the camera 
   // Always orthogonal to the forward vector 
   var right = Vector3(forward.z, 0, -forward.x); 

  
 if (Input.GetKey ("w")) { 
   rigidbody.AddTorque(right * speed * Time.deltaTime); 
   
   } 

if (Input.GetKey("s")) { 
   rigidbody.AddTorque(right * -speed * Time.deltaTime); 
   } 
    
if (Input.GetKey ("d")) { 
rigidbody.AddTorque(forward * -speed * Time.deltaTime); 
} 

if (Input.GetKey ("a")) { 
rigidbody.AddTorque(forward * speed * Time.deltaTime); 
 } 
 
 
 if (grounded)
    {
	
	var velocity = rigidbody.velocity;
	
	if (canJump  Input.GetButton("Jump"))
        {
            rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
        }
    }
 
 
   // We apply gravity manually for more tuning control
    rigidbody.AddForce(Vector3 (0, gravity * rigidbody.mass, 0));
    
    grounded = false;
 
 
}

 
 
 function OnCollisionStay ()
{
    grounded = true;    
}


function CalculateJumpVerticalSpeed ()
{
    // From the jump height and gravity we deduce the upwards speed 
    // for the character to reach at the apex.
    return Mathf.Sqrt(2 * jumpHeight * gravity);
}
 
[quote][/quote]

AddTorque is already on a per second basis I believe, so you don’t have to multiply by Time.deltaTime.

And I would recommend using Input.GetAxis() instead of Input.GetKey() for simplicity.

Ok, so i got the jumping problem sorted out but i still cant figure our how to get the AddTorque to rotate faster. Its making me MAD :x !!!

var speed = 300.0; 
var gravity = -5; 
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;


 function FixedUpdate() { 
 rigidbody.AddForce (Vector3(0, gravity, 0)); 
  
 var cameraTransform = Camera.main.transform; 

   // Forward vector relative to the camera along the x-z plane    
   var forward = cameraTransform.TransformDirection(Vector3.forward); 
   forward.y = 0; 
   forward = forward.normalized; 

   // Right vector relative to the camera 
   // Always orthogonal to the forward vector 
   var right = Vector3(forward.z, 0, -forward.x); 

  
 if (Input.GetKey ("w")) { 
   rigidbody.AddTorque(right * speed * Time.deltaTime); 
   
   } 

if (Input.GetKey("s")) { 
   rigidbody.AddTorque(right * -speed * Time.deltaTime); 
   } 
    
if (Input.GetKey ("d")) { 
rigidbody.AddTorque(forward * -speed * Time.deltaTime); 
} 

if (Input.GetKey ("a")) { 
rigidbody.AddTorque(forward * speed * Time.deltaTime); 
 } 
 
 
 if (grounded)
    {
	
	var velocity = rigidbody.velocity;
	
	if (canJump  Input.GetButton("Jump"))
        {
            rigidbody.velocity = Vector3(velocity.x, jumpHeight , velocity.z);
        }
    }
 
 
   // We apply gravity manually for more tuning control
    rigidbody.AddForce(Vector3 (0, gravity * rigidbody.mass, 0));
    
    grounded = false;
 
 
}

 function OnCollisionStay ()
{
    grounded = true;    
}

Good use of emoticons :smile:! (Sorry, I have no idea how to help you.)

Angular velocity is clamped in the project physics settings. Raise the value if you want your ball to rotate faster.

Did you try my advice? Take out the Time.deltaTime in AddTorque

Thank You, i fixed it.