Hello everyone
I need some help with my physics
I have a box collider, witch act like the bounds of my player
This collider, has a layer name set to “No Calculation” because this doesn’t do anything in the game
Then I created a bullet, I attach a script into it
public class BulletController : MonoBehaviour {
[SerializeField]
float bulletSpeed;
[SerializeField]
Rigidbody2D bullerRB;
[SerializeField]
Vector2 moveDir;
public void setBulletDir(Vector2 dir) {
moveDir = dir;
}
// Update is called once per frame
void Update() {
bullerRB.velocity = moveDir * bulletSpeed;
}
private void OnTriggerEnter2D(Collider2D other) {
Destroy(gameObject);
}
private void OnBecameInvisible() {
Destroy(gameObject);
}
}
and I have the player, that is able to fire, and a shotpoint
[SerializeField]
Rigidbody2D PlayerRB;
[SerializeField]
float moveSpeed;
[SerializeField]
float jumpForce;
[SerializeField]
Transform groundPoint;
[SerializeField]
LayerMask whatIsGround;
private bool isOnGround;
[SerializeField]
Animator animator;
[SerializeField]
BulletController shotToFire;
[SerializeField]
Transform shotPoint;
// Update is called once per frame
void Update() {
Vector2 currentVelocity = PlayerRB.velocity;
isOnGround = Physics2D.OverlapCircle(groundPoint.position,
.2f, whatIsGround);
currentVelocity.x = Input.GetAxisRaw(HORIZONTAL) * moveSpeed;
if (currentVelocity.x < 0) {
transform.localScale = new Vector3(-1f, 1f, 1f);
}
else if (currentVelocity.x > 0) {
transform.localScale = Vector3.one;
}
if (Input.GetButtonDown(JUMP) && isOnGround) {
currentVelocity.y = jumpForce;
}
if (Input.GetButtonDown(FIRE)) {
Instantiate(shotToFire, shotPoint.position,
shotPoint.rotation).setBulletDir(new Vector2(transform.localScale.x, 0));
}
PlayerRB.velocity = currentVelocity;
animator.SetBool("IsOnGrund", isOnGround);
animator.SetFloat("Spped", Mathf.Abs(PlayerRB.velocity.x));
}
the issue comes when I fire a bullet, because is hitting the box collider of the world (No calculations) and disappearing, also, when I move and shoot the bullet disappear
so apparently, the shot is interacting with each other and are interacting with the No Calculations layer
I do not understand, because I turned off any interactions
2024-10-23 22-12-18.zip (9.1 MB)
as you can see from the video, the bullet is hitting the Camera Bounds, which is set to the calculations layer, and the standing sprite, which is part of the player.
None of these are supposed to hit, because I SET the physics settings NO INTERACTION


