#cant change positions on a global script
23 messages · Page 1 of 1 (latest)
send the code please
im gonna set up a on variable and == it to true on start and then turn it off
@onready var catball = preload("res://All_Scenes/Weapons/CatBall/CatBallWeapon.tscn")
@onready var player = $".."
var timer := Timer.new()
var enemy_list = []
var CatBallLevel = 1
var BaseDmg = 2
var Cooldown = 1
var RealDmg:
get():
return BaseDmg * CatBallLevel
var speed = 50
func _ready():
timer.wait_time = Cooldown
timer.one_shot = false
add_child(timer)
timer.start(Cooldown)
z_index += 1
func _on_detect_enemys_body_entered(body):
if enemy_list.has(body):
pass
if body.is_in_group("enemy"):
enemy_list.append(body)
func _init():
spawn()
func _on_detect_enemys_body_exited(body):
if body.is_in_group("enemy"):
enemy_list.erase(body)
func _on_player_cat_ball_equip():
Find_Enemy()
func Find_Enemy():
for enemy in enemy_list:
var enemy_direction = self.global_position.direction_to(enemy.global_position)
var enemy_distance = $"..".global_position.distance_to(enemy.global_position)
var angle = enemy_direction.angle()
if enemy_distance > 0:
rotation = angle
velocity = enemy_direction * speed
move_and_slide()
func spawn():
self.global_position = $"..".global_position
func _on_area_2d_body_entered(body):
if body.is_in_group("enemy"):
enemy_list.erase(body)
spawn()
print("respawned")
```
what are you trying to modify on the window?
it says window cuz it cant get players position
I think the script loads before the player thats why it cant get it
is that what globals do ?
does it happen in spawn() ?
the parent of an autoload will always be the window
I'm not sure what your script is doing
its how it was sent here is why its like that
when you make a script an autoload it doesn't make thr script itself global but a copy of it
it will be placed at /root/ScriptName
and I doubt you want your player there
im not really understanding this unless you know how to get scene variables from other scenes this is all I know is to make it global
make an autoload with just the variables you want globally and make your player script access these
this object is like a projectile so im not really sure how id do that and id need the projectiles movement script in its thing
Here's an example
var player_speed := 10.0
func _physics_process()
move_and_slide(something * Globals.player_speed)
so this script I make global but with only the variables ?
Yes make an autoload with just variables for now
I think ik what to do so ill be right back
hey I wont lie I kinda feel like im going insane and I feel like ive came to a realization I may have been over thinking this