- Home /
The Cube object moves through other cube objects and does not move smoothly on other cube objects,Cube object moves through other cube objects and does not move smoothly
Hi everyone! Currently, I am making some kind of labyrinth game. My main character is a cube object that is moving through the walls which are composed of other cube objects. I do not want this to happen. The character has rigidbody, a box collider, because of this post I changed it to sphere collider later, I freeze the rotation, the object is NOT kinematic and the collision detection is continous. I also move the object with rigidbody.MovePosition. I could not make addforce work when I was using a box collider with frozen rotations. The walls does not have rigidbody. The character can move like a couple of cms inside the walls when you try to move it diagonally. Changing the collider to sphere solved this issue but I do not know why and I would like to learn if there is any other options using box collider. The situation is like this:
My second problem is that my floor is also made from cube objects stacked together and the character even with the sphere collider cannot move smoothly on it. I created a physics material without any static or dynamic friction and fed it into the floor box collider but it did not work. It stills moves like something is holding it. I do not want my object to float so this is not an option. Also, I do not know why maybe it is because of friction but like I said I do not use addforce, the object keeps moving after I release the key. I would be more than happy if someone could help.
public class Movement : MonoBehaviour
{
[SerializeField] PlayerManager playerManager;
[SerializeField] float speed;
public Rigidbody rb;
public Vector3 movement;
void Start()
{
rb = this.GetComponent<Rigidbody>();
}
void Update()
{
movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
movement.Normalize();
}
private void FixedUpdate()
{
moveCharacter(movement);
}
void moveCharacter(Vector3 direction)
{
rb.MovePosition(transform.position + (direction * speed * Time.deltaTime));
//rb.AddForce(direction * speed);
}
private void OnCollisionEnter(Collision collision)
{
}
}
EDIT 1: Apparently, the smoothness problem is not caused by the cube objects. I changed the Fixed Timestep to 0.002 and the issue is solved. Also, for anyone interested the object was sliding when I release the keys. The solution to that was using GetAxisRaw rather than just GetAxis. I would like to know if there is another solution to the so-called smoothness problem without changing the timestep.
Your answer
Follow this Question
Related Questions
friction problem 1 Answer
Using WASD keys instead of mouse to roll ball? 1 Answer
How to move a cube constantly with GetKeyDown 3 Answers
Buggy Collision 1 Answer