Collision problem
Asked Answered
L

5

0

So i have the floor:

also i have a block:

I have a bullet:

bullet code:


const SPEED = 5.0
@onready var bullet = $bullet_base
@onready var raycast = $RayCast3D
@onready var particles = $GPUParticles3D

func _process(delta):
	bullet.position += bullet.transform.basis * Vector3(0,0,-SPEED) * delta
	if raycast.is_colliding():
		print(raycast.get_collider())
		print("bullet_hit")
		bullet.visible = false
		particles.emitting = true
		await get_tree().create_timer(1).timeout # <---- timer
		queue_free()

bullet raycast settings:

And the logic is like: when bullet have collision with the floor or block -> it will be destroyed and particles appears.
But instead of logic above i have this:

if be short, i don't understand how collisions works here, i don't like how it's made.
is there some actions like "on collision" or "if object have collision"? (except the area3D call)

Lymphosarcoma answered 8/12, 2023 at 16:16 Comment(0)
L
0

Lymphosarcoma You have two problems here; detection and proper response. First make sure detection is working. Since rayhit is updated per physics frame better to test it in _physics_process() instead of _process(). Once your code properly prints "bullet hit" you can go on to fix the response.

Never await() in _process() or _physics_process(). Instead, delete the bullet immediately and spawn the particle effect scene at its position.

Lunn answered 8/12, 2023 at 19:41 Comment(0)
L
0

Lunn i have tried with/without await() , also with _physics_process() instead of _process(), nothing happened.
it's always the same result (as on my gif above)
i don't see "bullet_hit" output.

Lymphosarcoma answered 8/12, 2023 at 19:48 Comment(0)
L
0

Lymphosarcoma i don't see "bullet_hit" output

Then there's a problem with your raycast setup. For start, elongate the ray and enable collision shapes visibility to visually check if the ray is pointing in the intended direction. Also check that collision layers/masks are properly set up on areas.

Lunn answered 8/12, 2023 at 20:9 Comment(0)
L
0

Lunn here's my scene:

also, i noticed when i'm too close to the object, it works sometimes:

Lymphosarcoma answered 8/12, 2023 at 20:19 Comment(0)
L
0

Lymphosarcoma You should check how the ray looks in an instanced bullet. If that instance is scaled and/or the bullet is moving fast, the ray may end up being too short to register a hit.

And again, never ever await it _process(). It will always screw things up in multiple ways.

Lunn answered 8/12, 2023 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.