Copying Barbarian Blaster, Same Code Different Result

Hi everyone. I am trying to copy every game by myself so I can excel my knowledge. I am making projectiles and in the course code there is a line like this (maybe not exact) projectile.global_posiiton = turret.global_position. if I use the same my projectiles are spawning somewhere else but if I make projectile.global_position = Vector3.ZERO than projectiles spawn inside turret (at center of turret)
IN PROJECTILE TOP LEVEL is checked and in code I am setting its global position but it acts like local. Why is that happening?

resim

Hi,

theres a slight change you could make here to test.

var new_projectile = projectile.instantiate()
add_child(new_projectile )

if you could move the add(child) to just under the projectile instantiate and then test again.

my understanding of this, and its possibly a slight godot specific issue.
but, the projectile isnt inside the games scene tree until we call add_child()

and when we try and set the global_position before its been added to the scene tree, godot doesnt like it, and just returns a tranform3D and doesnt set it, so when we add child, it just creates it at the local position.

moving the add_child to before we set the global position of the projectile, will allow godot to change its transform properties and you should see it in the middle of the screen.

see how that goes and let us know.

Darren

2 Likes

thank you it resolved the issue :blue_heart: how can I learn this type of specific usages. is it just experience or there is a source to look pipeline of generic functions

sweet, glad its working for you :slight_smile:
this one, i believe was covered briefly in one of the courses, just cant remember for the life of me which and where i seen it.

but, yea most of it will come after a while, especially when you start tinkering and changing things up and hit an error or something thats not quite right.

practice and playing around with some things is the best way and will come in time :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms