- Home /
Question by
Glemau · Jun 09, 2018 at 10:42 PM ·
c#scripting problemphysicsball
Scripted Ball Bouncing igher and higher
Hi, I have scripted a ball that should bounce around a cylinder. The problem is, that the ball keeps bouncing higher instead of staying at one height.
//bouncing
currentGravity -= Time.deltaTime * gravity;
if (Input.touchCount > 0 && touching == false || Input.GetKey(KeyCode.Space))
{
touching = true;
if(currentGravity > 0){
currentGravity = -currentGravity;
}
}
if(Vector3.Distance(Vector3.zero, playerObject.position) <= 3 && currentGravity < 0){
currentGravity = -currentGravity;
}
Debug.Log("currentGravity = " + currentGravity);
if(touching){
currentGravity += currentGravity * gravityModifier;
}else {
currentPosition += currentGravity;
}
playerObject.localPosition = new Vector3(currentPosition, 0, 0);
Why does it do this? May it be because the ball starts reversing a slight moment after being at a distance of 3?
Comment
Your answer
Follow this Question
Related Questions
I need help converting this script from zilch to js 0 Answers
After exporting my project from my PC to my laptop the physics of my game work differently. 1 Answer
I am trying to launch a 2d object toward the mouse. 1 Answer
How to make object bounce from one bound to another? 0 Answers
how to make trampoline in unity 3D 1 Answer