why it collide yet sometime didn't update as collide?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

why it collide yet sometime didn’t update as collide? https://youtu.be/5wAEvCWrTyM
something wrong with code? or something else?

func _physics_process(delta: float) -> void:
	if path.size() > 1:
		var distance = get_position().distance_to(path[0])
		if distance > 2 :
			set_position(get_position().linear_interpolate(path[0],(move_speed*delta)/distance))
		else:
			path.remove(0)
	else:
		move_speed =0
	
	var collision = move_and_collide(Vector2.ZERO)
	if collision:
		var colider = collision.collider
		if colider.is_in_group("bullet") :
			print("collider")
			queue_free()

var colider
if colider

You sure those are supposed to only have one “L” each?

System_Error | 2020-03-20 13:37

yeah, i make var bit different than collider

potatobanana | 2020-03-20 13:58

Which part is not working? Detecting the collision itself or detecting that the collider is in the group “bullet”? And why are you using move_and_collide with a zero-vector?

njamster | 2020-03-20 14:31

they colliding(colliding always working), but sometime it detecting that the collider is in the group “bullet”, sometime not.

because enemy move use navigation2d? i dont know what to put in that.

potatobanana | 2020-03-20 15:09

because enemy move use navigation2d? i dont know what to put in that.

I never used Navigation2D, so I might be wrong. But instead of directly setting the position of your enemy with set_position you could also use move_and_collide, isn’t it? With move_and_collide you check if something is blocking the way (described by velocity). If I only want to check for collisions where I already am, I’d use an Area2D.

they colliding, but sometime it detecting that the collider is in the group “bullet”, sometime not.

Assuming that move_and_collide still registers every collision at the current position even when the velocity-vector is equal to zero (which I haven’t tested, but you said it does) and granted that you never have issues accessing the collider (which should lead to an error if it happens), the only potential problem left would be that the collider isn’t in the correct group. If you sure it is, I have absolutely no idea. :frowning:

njamster | 2020-03-21 15:39

can area2D detect kinematic2D? or should i put area2D for both bullet and mob? or remove kinematic2D and use area2d? can area2D make bounce effect??
i think to change to area2D.

and when it didn’t detect is_in_group, error didn’t show up.

file if you want to check TD tower 9march2020.rar - Google Drive

potatobanana | 2020-03-21 17:09

can area2D detect kinematic2D?

Yes.

or should i put area2D for both bullet and mob?

That would work as well. If it makes sense for your project, is a different question.

can area2D make bounce effect??

No. Or at least it’s a lot easier to do with a KinematicBody2D or RigidBody2D.

file if you want to check

I’m confused. In that project you don’t check for the group of the collider, but for the name. I already told you, that’s not a good idea over here.

njamster | 2020-03-21 20:36

this consider check name? not group?
enemy

var collision = move_and_collide(Vector2())
	if collision:
		var colider = collision.collider
		if colider.is_in_group("bullet") :
			print("collider")
		
			queue_free()

		if colider.is_in_group("tower_need_to_deffend") :
			print("collider with player tower")




			global_data.player_life -=1
			queue_free()

enter image description here

potatobanana | 2020-03-22 02:26