Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Problem with making an object bounce.

$
0
0
I have this script attached to a Sphere with a Rigidbody: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { Rigidbody rb; public float forceStrenght = 10; public bool isGrounded; public float bounceStrenght = 3; // Use this for initialization void Start () { rb = GetComponent (); } // Update is called once per frame void Update () { if (Physics.Raycast (transform.position, new Vector3 (transform.position.x, transform.position.y - .1f, transform.position.z), 1f)) { isGrounded = true; } else { isGrounded = false; } if (Input.GetMouseButtonDown (0)) { rb.AddForce (0, -forceStrenght, 0, ForceMode.VelocityChange); } if (isGrounded) { rb.AddForce (0, bounceStrenght, 0, ForceMode.VelocityChange); } } } My problem is that sometimes the object bounces bigger sometimes smaller. I don't want that, I want the object always reach the same height if I don't interupt it by pressing the LMB.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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