- Home /
GameObject passes through objects
My player passes through all objects when its moving. I tried to set the collision detection to continous but no success. This is my code to move:
var x = Input.GetAxisRaw("Horizontal") * Time.deltaTime * 500.0f;
var z = Input.GetAxisRaw("Vertical") * Time.deltaTime * 30.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
I guess I have to move the rigidbody but how? I tried this:
Vector3 movement = new Vector3(x, 0.0f, z);
rb.AddForce(movement * speed);
Instead of the transform.Rotate and translate but the player cant move properly. So help me please
The player and other objects needs to have collider component or won't colide. The Rigidbody does not collide, is a component to create mass and physical behavior.
Just checking basic stuff, also make sure "Is Trigger" is unchecked and how the script is using the collider. Sometimes a collider is used just to fire events or to create effects ins$$anonymous$$d of actually collide.
Answer by metalted · Jun 27, 2019 at 12:10 PM
Moving the rigidbody can be done using rigidbody.moveposition(). Then you still have to check for some kind of collision detection so your object doesn't move through objects. There is some nice information on this answer page : https://answers.unity.com/questions/960427/rigidbodymoveposition-skips-collisions.html . If you want something easy out of the box, you might want to try using a CharacterController. This uses a special move function that takes collisions into consideration so it can't move through objects.