I want that If my player Jumps I get a Jump sound.
Asked Answered
I

6

0

I want that If my player Jumps I get a Jump sound.
So I used this code:

extends AudioStreamPlayer

func _process(delta):
	if Input.is_action_pressed("jump"):
		$Jump.play()

I did coding in a music node

But I got an error: attempt to call function 'Play' in base 'null instance' on a null instance

Download the code: https://github.com/jipiee/Questions

Thanks in advance

V.3.5.2

Internalize answered 18/6, 2023 at 12:1 Comment(0)
O
0

ok so.. you don't wanna put that code in an Audio Stream Player

the way that worked best for me is implementing the code in your CharacterBody/KinematicBody
kinda like this:

if Input.is_key_pressed(KEY_SPACE) and is_on_floor
       	$Jump.play()

you can change the $Jump into whatever your AudioStreamPlayer is named.
if you don't use "is_key_pressed" in your player movement code you can instead use is_action_pressed("ui_accept"):
also the Is_on_floor is completely optional

Oxalate answered 18/6, 2023 at 12:11 Comment(0)
O
0

Oxalate P.S the $Jump.play() is supposed to be intended but the tab key won't work

Oxalate answered 18/6, 2023 at 12:12 Comment(0)
I
0

Oxalate In wich function should I put it?

Internalize answered 18/6, 2023 at 13:16 Comment(0)
I
0

Internalize If I put it in the func x_movement(delta: float) -> void: I still get the same error

Internalize answered 18/6, 2023 at 13:23 Comment(0)
A
0

Add a tag to this topic that indicates your Godot version.

Ardyth answered 18/6, 2023 at 14:40 Comment(0)
I
0

It works TYSM

Internalize answered 18/6, 2023 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.