func fireprojectile():
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if !gun_anim.is_playing():
gun_anim.play(“gun_anim”)
else:
print(“FAIlED”)
Question
i have everything set up after a tutorial but it wont play the animation?
func fireprojectile():
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if !gun_anim.is_playing():
gun_anim.play(“gun_anim”)
else:
print(“FAIlED”)
i have everything set up after a tutorial but it wont play the animation?
Need a bit more info to go on to help:
Do you get any errors?
Where is fireprojectile
being called from?
Is the tutorial online so I can have a quick look to see what should be happening?
no erros, but just wont work, no idea where fireprojectile is from
Ah ok, are you just using the tutorial as the basis for your own project?
It looks like if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
should be in the _physics_process
part of your player.gd script like
func _physics_process(delta):
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
fireprojectile()
You could try changing that in the script and see if it works, if not can you paste the full contents of your player.gd here for me to look at.
heres the full code, i cant use another func _physics_process(delta) but cant put the if statement in the other one
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 2.75
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
var mouse_sensitivity = 0.3
var yaw = 0.0
var pitch = 0.0
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
yaw -= event.relative.x * mouse_sensitivity
pitch -= event.relative.y * mouse_sensitivity
pitch = clamp(pitch, -90, 90)
$Camera3D.rotation_degrees.x = pitch
rotation_degrees.y = yaw
if Input.is_action_just_pressed("pause"):
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func input(event):
if event.is_action_pressed(“fullscreen”):
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
@onready var gun_anim = $glock19/AnimationPlayer
func fireprojectile():
if !gun_anim.is_playing():
gun_anim.play("gun_anim")
else:
print("Animation is already playing")
sorry for weird formating
Edit: i figured it out youre a lifesaver seriously thank you so much