Added resources to the game and prepared scripts for later usage
This commit is contained in:
+8
-39
@@ -11,7 +11,14 @@ public partial class Camera3d : Camera3D
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if(!canMove) return;
|
||||
if (canMove) MoveCamera(delta);
|
||||
|
||||
if (!canMove) return;
|
||||
|
||||
}
|
||||
|
||||
public void MoveCamera(double delta)
|
||||
{
|
||||
float d = (float)delta;
|
||||
|
||||
var rotation = RotationDegrees;
|
||||
@@ -37,42 +44,4 @@ 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user