Right now, I have a collision code on my Player scene like this:
for index in range(get_slide_collision_count()):
var collision:KinematicCollision3D = get_slide_collision(index)
var collider:Object = collision.get_collider()
if collider:
collider.queue_free()
Player scene is CharacterBody3D which checks for collision in _physics_process(). There is a Bullet scene which is RigidBody3D that will collide with the player.
From the code above, it works. Yet every time the bullet hits the player, the bullet disappeared correctly, but the player got nudged a bit. I do not want the player’s position to change when the player got hit.
How can I make it so the Bullet will not affect the player’s position?
Maybe try to put your code in the RigidBody3D._integrate_forces() method, which is called before any physics happen. Not sure if this will fix your issue, but is worth a shot.
@wchc Unfortunately, I have the Player gdscript checking for all the collisions and call appropriate collision logics in the colliding collider, and the Player is CharacterBody3D, not RigidBody3D.
In this case, I think having the Player checking for all the incoming bullets would have better performance than having all bullets checking against the player.
I suggested that to at least see if this will fix your issue. Because if it does fix your issue, then you know what’s the rootcause (physics collision calculated before the bullet node is freed) and then you can later find ways to optimize it.
After experimenting some more, I got what I wanted.
I made the Bullet scene to be in a collision Layer just for Bullets.
I added a “BulletChecker” Area3D as a Child of the Player for checking the bullets and do queue_free() in there. The “BulletChecker” Area3D has a collision Mask on the layer used for the Bullets.
Finally, the Player CharacterBody3D’s Collision Mask is set so that it will check against Floors, Walls, etc., but not the layer used for the Bullets. This way, the CharacterBody3D Player and RigidBody3D Bullets will still abide their physics attributes but their physics attributes will not interact with each other.