The raycast from my gun start at the main câmera. But if the angle is too low (if i look to the floor), the raycast hits the player. If i keep shooting at the floor, i die (whatheheck). I was previously raycasting from an empty GameObject in front of the camera, and was working just fine.
My script just in case:
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out ray, range)) {
life = ray.transform.GetComponent<life>();
if (life != null) {
life.TakeDamage(damage);
}
rigidbuddy = raio.transform.GetComponent<Rigidbody>();
if (rigidbuddy != null) {
rigidbuddy.AddForce(-transform.forward * 40 * danodaarma);
}
}
Usual everyday stuff. I don’t know why such a bug happens.
THIS! The original question is not related to my issue, but if anyone is having trouble with a player controller reacting in a weird way when the player's layermask is set to collide with its own layer, then setting queries off is the solution. I hope this can help someone else out. You can turn this setting off through Edit -> Project Settings -> Physics2D -> Queries Start In Colliders.
– Mattheon