Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision of CharacterBody3D does not respect position set after instantiating (first tick only?) #58445

Closed
vermeeren opened this issue Feb 22, 2022 · 1 comment

Comments

@vermeeren
Copy link

vermeeren commented Feb 22, 2022

Godot version

4.0 master e17c29a

System information

Debian bookworm (testing)

Issue description

Following the first 3D game tutorial with Godot 4 I run into the issue when upon instantiating the mob there is unexpected collision occurring in the exact middle position of the playing field, which presumably is the 0,0,0 position.

bug.mp4

The logic here is very simple. When the timer triggers in the Main scene to spawn a mob:

# main.gd
func _on_mob_timer_timeout():
	var mob = mob_scene.instantiate()
	$SpawnPath/SpawnLocation.unit_offset = randf()
	add_child(mob)
	mob.initialize($SpawnPath/SpawnLocation.position, $Player.position)

# mob.gd
func initialize(start_pos, player_pos):
	position = start_pos
	look_at(player_pos)
	rotate_y(randf_range(-PI / 4, PI / 4))

	var speed = randf_range(min_speed, max_speed)
	motion_velocity = Vector3.FORWARD * speed
	motion_velocity = motion_velocity.rotated(Vector3.UP, rotation.y)

I also tried enabling the Mob's CollisionShape3D Disabled parameter using the inspector and then adding to the bottom of mob.gd's initialize():

$CollisionShape3D.set_deferred("disabled", false)

Behaviour is the same, which is strange as the Mob position is absolutely set before enabling collisions.

Perhaps something changed in Godot 4 and I'm doing it wrong but it feels like there is a single-tick delay on updating the collision's position somehow, as graphically (including with debug show hitboxes) everything looks good and collision with mobs also works properly.


Changing Mob like this:

func initialize(start_pos, player_pos):
	...
	$CollisionShape3D.disabled = true

func _physics_process(_delta):
	$CollisionShape3D.set_deferred("disabled", false)
	move_and_slide()

Resolves the issue, which makes me believe it is indeed a "tick 0" issue where somehow the collision's position is not updated properly.

Steps to reproduce

Open up attached project and play.

Minimal reproduction project

squash_the_creeps.zip

@rburing
Copy link
Member

rburing commented Mar 13, 2022

This is a duplicate of #58132. In my view the tutorial code is flawed; it is a documentation issue of the type described in #45638.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants