Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mate_Dev |
In minute 18:10, i do the same as he did but it dont works to me:
code:
extends Node
export var fire_rate = 0.5
export var clip_size = 5
export var reload_rate = 1
onready var raycast = $"../Head/Camera/RayCast"
var current_ammo = 0
var can_fire = true
var reloading = false
func _process(delta):
if Input.is_action_just_pressed("primary_fire") and can_fire:
if current_ammo > 0 and not reloading:
print("Fired Weapon")
can_fire = false
current_ammo -= 1
check_collision()
yield(get_tree().create_timer(fire_rate), "timeout")
can_fire = true
elif not reloading:
print("Reloading")
reloading = true
yield(get_tree().create_timer(fire_rate), "timeout")
current_ammo = clip_size
reloading = false
print("Reload complete")
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)
first make a 2d game.
Your first 2D game — Godot Engine (latest) documentation in English
ramazan | 2022-01-30 20:19
Thanks for the tip but i just solve it.
Mate_Dev | 2022-01-31 19:52
I am aware . It’s best for you to start with simple games first. I started the same way. Just a suggestion.
ramazan | 2022-01-31 21:56
In what way doesn’t it work?
SteveSmith | 2022-02-08 02:21