I have just started learning Godot and already know a decent bit of C# from unity. I am trying to set up a 3D character rig. The function should be there as the docs all say it should but when I compile this code:
using Godot;
using System;
public partial class world_control : Node
{
SceneTree tree;
Node3D camera;
Node3D head;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
tree = GetTree();
camera = tree.get_current_scene().find_child("camera", false, false);
head = tree.get_current_scene().find_child("head", true, false);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
camera.set_global_position(head.get_global_position());
camera.set_global_rotation(head.get_global_rotation());
}
}
It gives me these errors:
/***/Godot/Hand_Cannon/world_control.cs(14,17): 'SceneTree' does not contain a definition for 'get_current_scene' and no accessible extension method 'get_current_scene' accepting a first argument of type 'SceneTree' could be found (are you missing a using directive or an assembly reference?)
/***/Godot/Hand_Cannon/world_control.cs(21,35): 'Node3D' does not contain a definition for 'get_global_position' and no accessible extension method 'get_global_position' accepting a first argument of type 'Node3D' could be found (are you missing a using directive or an assembly reference?)
(I have left out a few more errors but basically all of the functions cause this excact error)
Extra Information: Godot 4.1 with C# .NET 8 (Installed on day of posting) Mac OSX 13.5.1
I can and am very willing to provide more info if needed!
This is a problem in which I simply don't know what to try. I am very new to Godot having installing it today. Nothing so far has worked, in fact I did not even know that the values had getter functions!
C# methods and properties in Godot use PascalCase, while GDScript methods use snake_case. Global methods in C#, such as Print, can be accessed through the GD static class. Apart from that, you can try the code below for your use case:
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
SceneTree tree = GetTree();
camera = (Node3D)tree.CurrentScene.GetNode("camera", false, false);
head = (Node3D)tree.CurrentScene.GetNode("head", true, false);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
camera.Position = head.Position;
camera.Rotation = head.Rotation;
}