I've come across an odd effect in Unity and would like to understand why it's happening. Using some simple code I've achieved a horizontal movement effect, of a ball across a flat square surface, yet the movement in any given direction is bumpy, as in, it's like the ball is bouncing slowly until it settles in a hole when the key is let up. I've never noticed anyone else's player object doing this, and there doesn't seem to be any instances of it out there, based on my research. One might describe it as "rolling through the inside of an egg carton". Does anyone knows why this is happening, if it's normal, or at the fault of my code?
Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody rb;
public float speed;
//
void Start()
{
rb = GetComponent<Rigidbody>();
}
//
void FixedUpdate()
{
var gravity = new Vector3(Input.acceleration.x, Input.acceleration.z, Input.acceleration.y) * 9.8f;
rb.AddForce(gravity * rb.mass, ForceMode.Acceleration);
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontal, 0.0f, vertical);
rb.AddForce(movement * speed);
}
}
And here's a GIF of what's happening:
ForceMode.Acceleration
then you don't need to take the mass off the rigidbody into account. Making mass irrelevant is the whole purpose of that option. But that just by the way. \$\endgroup\$