Question by
ronald677br · Jul 16, 2016 at 11:26 PM ·
colliderspeedjumpingball
Object jumping at high speed!
Hi guys, from the last few weeks I've been working at this "Rolling Ball" style game, but this problem is driving me mad. (Sorry for my English, I'm Brazilian)
I have the standard Unity sphere with this script and a rigidbody attached to it:
void Start() {
InvokeRepeating("decreaseTimeRemaining", 1.0f, 1.0f);
Physics.gravity = grav;
}
void OnGUI()
{
GUI.Box(new Rect(10, 10, 50, 20), "" + time.ToString("0"));
}
void FixedUpdate() {
Vector3 SuperBoost = boostZ + (boostZ / 2);
if (Input.GetMouseButton(0)) { z = 1; }
MoveX = Input.GetAxis("Mouse X");
movement = new Vector3(MoveX, 0.0f, z);
GetComponent<Rigidbody>().AddForce(movement * speed);
if (boost)
{
if (time > 0)
{
GetComponent<Rigidbody>().AddForce(boostZ);
if (boostlvl == 2)
{
GetComponent<Rigidbody>().AddForce(boostZ + boostAdd);
}
if (boostlvl == 3)
{
GetComponent<Rigidbody>().AddForce(boostZ + boostAdd * 2);
}
if (boostlvl >= 4)
{
GetComponent<Rigidbody>().AddForce(boostZ + boostAdd * 3);
}
}
time -= Time.deltaTime;
if (time <= 0)
{
boostlvl = 0;
boost = false;
}
}
if (jump) {
GetComponent<Rigidbody> ().AddForce (boostY);
jump = false;
}
Debug.Log(boostlvl);
Debug.Log(time);
}
void OnTriggerEnter(Collider colider){
if (colider.gameObject.tag == "Pickable") {
time = 2;
boostlvl++;
boost = true;
}
if(colider.gameObject.tag == "jumpBox"){
jump = true;
}
colider.gameObject.SetActive (false);
}
The problem is that when my sphere goes at high speed, it sometimes jumps when hitting with platforms that are adjacent to each other, even when they are at the same Y position. I've uploaded this video for better understanding: https://www.youtube.com/watch?v=lOpnINlDZZc
Please, help me! I've searched at tons of posts an no one has the answer for this!
Comment