- Home /
Ball bounces unexpectedly while rolling downwards
So I'm creating this game and its an endless ball roller type game, as of right now when the ball rolls downhill it bumps from time to time I don't know if its caused by misaligned platforms or some physics problem. The balls collision detection is set to continuous
I have attached my physics project settings
Below is the spawning script
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; public class PlayerCollision : MonoBehaviour { public TestCharacterController movement; public List startingDel; public List obPrefabs; public GameObject[] PrefabRoad; public GameObject player; public GameObject startingTele; public int setToTrue = 0;
private void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
Debug.Log("WE HIT");
movement.enabled = false;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "DelStart")
{
Destroy(startingDel[0]);
Destroy(startingDel[1]);
Destroy(startingDel[2]);
Destroy(startingDel[3]);
movement.yForce = 0f;
player.transform.position = new Vector3(0, 118f, 158f);
Destroy(startingTele);
}
if (other.tag == "SpawnTrigger")
{
MoveRoad();
}
}
// Start is called before the first frame update
void Start()
{
if (obPrefabs != null && obPrefabs.Count > 0)
{
obPrefabs = obPrefabs.OrderBy(r => r.transform.position.z).ToList();
}
}
public void MoveRoad()
{
GameObject movedRoad = obPrefabs[0];
obPrefabs.Remove(movedRoad);
float newZ = obPrefabs[obPrefabs.Count - 1].transform.position.z;
// Debug.Log(newZ);
newZ += 26.6623f;
float newY = obPrefabs[obPrefabs.Count - 1].transform.position.y - 4.7013f;
// Debug.Log(newY);
movedRoad.transform.position = new Vector3(0, newY, newZ);
obPrefabs.Add(movedRoad);
}
// Update is called once per frame
void Update()
{
}
}
Here is the Character Script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TestCharacterController : MonoBehaviour { private Rigidbody rigidBody; public float zForce = 100f; public float yForce = 0f; private float xForce = 500f;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
rigidBody.AddForce(0, yForce, zForce * Time.deltaTime);
if (Input.GetKey("s"))
{
rigidBody.AddForce(0, 0, zForce * Time.deltaTime);
}
if (Input.GetKey("d"))
{
rigidBody.AddForce(xForce * Time.deltaTime,0,0);
}
if (Input.GetKey("a"))
{
rigidBody.AddForce(-xForce * Time.deltaTime, 0, 0);
}
}
}
maybe the gravity is not high enough, your picking up a lot of speed so your forward force might be more than your downward force.. hard to tell what is the issue.. could be a collision issue too.