This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
events:getting_started_with_godot_in_3d_part_2 [2020/03/31 17:12] admin |
events:getting_started_with_godot_in_3d_part_2 [2020/03/31 17:18] (current) admin |
||
|---|---|---|---|
| Line 68: | Line 68: | ||
| can_fire = false | can_fire = false | ||
| current_ammo -= 1 | current_ammo -= 1 | ||
| + | | ||
| + | yield(get_tree().create_timer(fire_rate), "timeout") | ||
| + | | ||
| + | can_fire = true | ||
| elif not reloading: | elif not reloading: | ||
| print "Reloading" | print "Reloading" | ||
| Line 75: | Line 79: | ||
| reloading = false | reloading = false | ||
| print "Reload complete" | print "Reload complete" | ||
| + | </code> | ||
| + | * Add a child node to the world, a static body, add a meshinstance to it as a child, called it enemy, make it a sphere | ||
| + | * Add a child node to the staticbody, a collision shape sphere | ||
| + | * Assign it to a group, (properties, node, "enemies") | ||
| + | * add new function: | ||
| + | <code python> | ||
| + | onready var raycast = $"../Head/Camera/RayCast" | ||
| + | func check_collision(): | ||
| + | if raycast.is_colliding(): | ||
| + | var collider = raycast.get_collider() | ||
| + | if collider.is_in_group("enemies"): | ||
| + | collider.queue_free() | ||
| + | print("Killed "+collider.name) | ||
| </code> | </code> | ||