Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Kayd |
So, I have a custom audio code on my tilemaps (for easy access to all child nodes) that calculates the distance between nodes and plays back sounds at particular levels. It is supposed to calculate the distance between the player and the event, and then calculate the playback level and pitch based on the distance.
Whenever I start up the game, however, it calculates the distance between the event and the player, but then doesn’t continuously update. I put this under “func _process(delta)” but that doesn’t continuously update the variable.
extends AudioStreamPlayer2D
var parent;
var player;
func _ready():
parent = getParent();
player = getParent().getParent().get_node("Player");
pass
func soundLevel(vectorOne, vectorTwo):
var distance = sqrt((((vectorTwo.x - vectorOne.x) * (vectorTwo.x - vectorOne.x)) + ((vectorTwo.y - vectorTwo.x) * (vectorTwo.y - vectorTwo.x))))
var logfactor = distance/100;
var levelfactor = (log((logfactor)/log(2)));
var decibels = (-1.6)*levelfactor;
return decibels;
func _process(delta):
var playerPosition = player.get_position();
var EventPosition = parent.get_position();
volume_db = soundLevel(playerPosition, EventPosition);
pass
How to I get it to update?
Also, why isn’t there a “get_parent” function for AudioPlayer2d?