- Home /
What is causing this odd physics behaviour?
The ball in my skeeball style arcade game rolls along a flat plane until it hits a ramp. The plane is FLAT. I have double and triple checked. There are no vertices or anything in the path, and everything is parallel. There is nothing else that affects rigidbodies there. In one specific place, just right of centre, the ball manages to get slightly deflected, as if there were some invisible bump. Here is a video showing what happens:
https://www.youtube.com/watch?v=ehqtocYnCJ8
This didn't happen on Unity 4.6, and I hadn't noticed it until the last update to the game (where I changed unrelated code, not affecting the ball or game table in any way.) In fact I hadn't noticed until someone brought it to my attention. It's only a small bump, but it is a physics based game, and when you throw hard enough to actually make a shot it can really throw the ball out of whack, or even off the table!
Here is the code for the ball movement, but by the time the ball has reached the glitchy bit, the user has no control and it is riding on the physics engine alone.
using UnityEngine;
using System.Collections;
public class Ballthrow : MonoBehaviour {
public float speed;
public bool intheZone = false;
public GameLogic gLogic;
public ballTrigger balltrigger;
public Settings gameSettings;
public bool canControl;
void FixedUpdate ()
{
//control the ball if you are in the ball zone!
if ((intheZone) == true) {
Time.timeScale = 1F;
}
if ((intheZone) != true) {
canControl = false;
if (Input.GetButtonDown ("SlowMo")) {
Time.timeScale = 0.4F;
}
}
if ((canControl) == true)
{
if(Input.GetAxis("Mouse X") < 0.1 && Input.GetAxis("Horizontal") < 0.1 && Input.GetAxis("Mouse Y") < 0.1 && Input.GetAxis("Vertical") < 0.1)
{
this.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
float moveHorizontalm = (Input.GetAxis ("Mouse X") * gameSettings.sensX);
float moveHorizontalj = (Input.GetAxis ("Horizontal") * gameSettings.sensX);
float moveVerticalm = (Input.GetAxis ("Mouse Y") * gameSettings.sensY);
float moveVerticalj = (Input.GetAxis ("Vertical") * gameSettings.sensY);
Vector3 movementm = new Vector3 (moveHorizontalm, 0.0f, moveVerticalm);
Vector3 movementj = new Vector3 (moveHorizontalj, 0.0f, moveVerticalj);
GetComponent<Rigidbody>().AddForce (movementm * speed * Time.deltaTime);
GetComponent<Rigidbody>().AddForce (movementj * speed * Time.deltaTime);
}
}
public void goHome()
{
transform.position = new Vector3(0f, 1.5f, -4.4f);
}
public void goAway()
{
transform.position = new Vector3(-10.549f, 9.0336f, -43.464f);
}
public void ballDelay()
{
StartCoroutine (waitForIt() );
}
IEnumerator waitForIt() {
//Debug.Log ("Ball reset");
yield return new WaitForSeconds (2);
canControl = true;
}
}
Does the ball have any scripts attached to it? If so, could you possibly post them, please.
my suspect is a addforce and constant force code is affecting it
Does moving the light change the position where that bump occurs?
Nope, moving/deleting/disabling the light does nothing.