Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | godotuser123 |
Hello
I want to spawn enemies in random position, what I did in short was to instance my enemy scene into my main scene(that’s where I code the spawning thing) and when I try to set the position of my enemy scene it says there is extension method for it
PackedScene foodsource;
public Node foodinstance;
public override void _Ready()
{
foodsource = GD.Load<PackedScene>("res://Food.tscn");
foodinstance = foodsource.Instance();
}
public override void _Process(float delta)
{
foodinstance.position // ***that's where there is error***
}
I would happy for some help(in c# if it’s possible)
c#I don’t know. if i’m not mistaken
add
add_child(foodinstance)
public Node foodinstance;
public override void _Ready()
{
foodsource = GD.Load<PackedScene>("res://Food.tscn");
foodinstance = foodsource.Instance();
add_child(foodinstance) ## this gdscript
ramazan | 2022-09-08 22:01
Yeah, But I can’t access the foodinstance
position
godotuser123 | 2022-09-09 09:19
try
{
//foodinstance.position // ***that's where there is error***
print(foodinstance) // this gdscript
// or
print(foodinstance.position) // this gdscript
}
ramazan | 2022-09-09 11:04
It doenst work because there is no position property for a Node
node
godotuser123 | 2022-09-09 11:15
res://Food.tscn = ?
what is type?
node type ? sprite , kinematicbody , area … etc
sorry
node type = Node
change Node = Node2d
ramazan | 2022-09-09 11:23
the food is scene is area2d if thats what you mean
godotuser123 | 2022-09-09 11:29
print(foodinstance) // output ?
ramazan | 2022-09-09 11:34
Output: area2d bro
godotuser123 | 2022-09-09 11:43
???
everything is correct. I don’t understand why there is a problem
position = Position
ramazan | 2022-09-09 11:45
Same here bro I really dont know what is the problem
godotuser123 | 2022-09-09 11:50
try
position = gdscript
Position = c#
ramazan | 2022-09-09 11:56
Tried it and I also tried globalposition
Doesnt work either
godotuser123 | 2022-09-09 11:59
try
position = gdscript
Position = c#
GD.Print(GlobalPosition);
ramazan | 2022-09-09 12:00
It will print the position of the root scene
godotuser123 | 2022-09-09 12:06
PackedScene foodsource;
public Node foodinstance;
public override void _Ready()
{
foodsource = GD.Load<PackedScene>("res://Food.tscn");
foodinstance = foodsource.Instance();
}
public override void _Process(float delta)
{
//foodinstance.position // ***that's where there is error***
foodinstance.Position;
}
ramazan | 2022-09-09 12:08
??
Its the same code
godotuser123 | 2022-09-09 12:13
“P” uppercase
position <==> Position
ramazan | 2022-09-09 12:19
Doesnt work bro
godotuser123 | 2022-09-09 15:11