Quantcast
Channel: Answers by "Stefan Alexander"
Viewing all articles
Browse latest Browse all 24

Answer by Stefan Alexander

$
0
0
Try using this Javascript: var rotationSpeed = 100; var jumpHeight = 8; var distToGround : float; function Start () { // Getting the distance from the center to the ground. distToGround = collider.bounds.extents.y; } function Update () { //Handle ball rotation. var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed; rotation *= Time.deltaTime; rigidbody.AddRelativeTorque (Vector3.back * rotation); if (Input.GetKeyDown(KeyCode.Space) && IsGrounded ()) { rigidbody.velocity.y = jumpHeight; } } function IsGrounded () : boolean { //Check if we are on the ground. Return true if we are else return null. return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1); }

Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>