Adding robots to the game and the ability to click on them

This commit is contained in:
=
2026-04-26 13:44:15 +02:00
parent bd9de785b4
commit 21199f8026
12 changed files with 155 additions and 9 deletions
+38
View File
@@ -36,4 +36,42 @@ public partial class Camera3d : Camera3D
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
}
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton mouse &&
mouse.ButtonIndex == MouseButton.Left &&
mouse.Pressed)
{
var camera = GetViewport().GetCamera3D();
Vector2 mousePos = mouse.Position;
Vector3 from = camera.ProjectRayOrigin(mousePos);
Vector3 to = from + camera.ProjectRayNormal(mousePos) * 1000f;
var spaceState = GetWorld3D().DirectSpaceState;
var query = PhysicsRayQueryParameters3D.Create(from, to);
query.CollisionMask = 1 << 1;
var result = spaceState.IntersectRay(query);
if (result.Count > 0)
{
Variant colliderVariant = result["collider"];
Node hit = colliderVariant.As<Node>();
GD.Print($"Clicked robot: {hit.Name}");
// Optional: call method on robot
if (hit is Node robot)
{
robot.Call("OnClicked");
}
}
}
}
}
+2
View File
@@ -8,5 +8,7 @@ public partial class GameData
public static int currentLayer = 0;
//The layer that is currently visible
public static int visibleLayer = 0;
//Determines if the player can move the camera or not (Necessary for input and options menu)
public static bool canMove = true;
}
+19
View File
@@ -0,0 +1,19 @@
using Godot;
public partial class UIHandler : Control
{
public override void _Ready()
{
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("codingwindow"))
{
GetNode<Panel>("./CodingWindow").Visible = !GetNode<Panel>("./CodingWindow").Visible;
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://bm7knir4552j5
+14
View File
@@ -0,0 +1,14 @@
using Godot;
public partial class Robot : Node3D
{
public void Move()
{
}
public void OnClicked()
{
GD.Print("Test!");
}
}
+1
View File
@@ -0,0 +1 @@
uid://e0pgy7jya41y
+7 -6
View File
@@ -16,12 +16,6 @@ public partial class World : Node3D
Layer layerNode;
private MultiMeshHandler multiMeshHandler;
FastNoiseLite noise = new FastNoiseLite()
{
NoiseType = FastNoiseLite.NoiseTypeEnum.Perlin,
Frequency = 0.05f,
Seed = 1337
};
public override void _Ready()
{
@@ -90,6 +84,13 @@ public partial class World : Node3D
HandleRenderData(BuildRenderData(currentLayer));
visibleLayer = currentLayer;
}
if (Input.IsActionJustPressed("spawn_robot"))
{
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.Position = map[0].tiles[1,1].Position;
AddChild(robot);
}
}
private void GenerateWorld()