- Home /
Rigidbody cube randomly stops moving?
I'm trying to move a cube with a rigidbody, on a straight surface which also has a box collider, however there are times when the cube would stop moving in all of a sudden, as though it hit a wall and unless i move it in the opposite direction it won't respond at all, even tho it still prints(""); message to the console. I added physics material, set dynamic and static drag to 0.1, i tried using the planes mesh collider instead of box collider, I adjusted the corners to make sure each side are touching, also tried AddForce(), and switching to different collider options (discreet, continuous etc) nothing seems to be fixing this. Any help is appreciated. I'm using the free mini-gold prefabs from the asset store btw.
private Rigidbody rb;
public bool reachedGoal = false;
Vector3 startPosition;
Vector3 goalPosition;
Vector3 dir;
public GameObject goal;
public float moveSpeed = 5f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
startPosition = transform.position;
goalPosition = goal.transform.position;
}
// Update is called once per frame
void FixedUpdate()
{
//if up/down arrow is pressed and gameobject hasn't made contact with goal
//call the movement method
if (Input.GetKey(KeyCode.UpArrow))
{
if (reachedGoal.Equals(false))
{
dir = Vector3.forward;
movePlayer(dir);
}
}
if (Input.GetKey(KeyCode.DownArrow))
{
if (reachedGoal.Equals(false))
{
dir = Vector3.back;
movePlayer(dir);
}
}
}
//check if player made contact with goal
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag.Equals("Finish"))
{
reachedGoal = true;
}
}
//add velocity to rigidbody in the direction * speed
private void movePlayer(Vector3 direction)
{
rb.velocity = direction * moveSpeed;
}
Answer by silvercrow17 · Dec 18, 2019 at 09:35 PM
Update: I've found a work around by adding a sphere collider or a script for the cube to rotate/flip around its edge.
Your answer
Follow this Question
Related Questions
Vertical push doesn't let the object fall down instantly 1 Answer
Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 0 Answers
Velocity Movement & Physics Interactions by Rigidbody2D 0 Answers
Applying proper drag and center of mass for a vehicle 1 Answer
Unity 2D platformer collider 1 Answer