Add rotations

This commit is contained in:
Sofia 2024-08-20 03:47:18 +03:00
parent 8bac5dbe77
commit 3f91453a1b
3 changed files with 31 additions and 1 deletions

View File

@ -141,6 +141,16 @@ place_block={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(202, 14),"global_position":Vector2(216, 84),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(202, 14),"global_position":Vector2(216, 84),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
] ]
} }
rotate_block_right={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(256, 16),"global_position":Vector2(270, 86),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
rotate_block_left={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(312, 24),"global_position":Vector2(326, 94),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
[internationalization] [internationalization]

View File

@ -17,6 +17,8 @@ namespace Gmtk24 {
public Node3D Hand; public Node3D Hand;
[Export] [Export]
public BuildingBlock HeldBlock { private set; get; } public BuildingBlock HeldBlock { private set; get; }
[Export]
public float RotateAmt = (float)(Math.PI / 12);
[Export] [Export]
public bool IsEnabled { private set; get; } = false; public bool IsEnabled { private set; get; } = false;
@ -24,6 +26,8 @@ namespace Gmtk24 {
private float CurrentYaw = 0; private float CurrentYaw = 0;
private float CurrentPitch = 0; private float CurrentPitch = 0;
private RandomNumberGenerator RNG = new RandomNumberGenerator();
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() { public override void _Ready() {
} }
@ -72,6 +76,13 @@ namespace Gmtk24 {
HeldBlock = null; HeldBlock = null;
} }
} }
if (@event.IsActionPressed("rotate_block_right")) {
HeldBlock.RotateY(RotateAmt);
}
if (@event.IsActionPressed("rotate_block_left")) {
HeldBlock.RotateY(-RotateAmt);
}
} }
public bool HoldBlock(BuildingBlock block) { public bool HoldBlock(BuildingBlock block) {
@ -79,9 +90,15 @@ namespace Gmtk24 {
return false; // TODO return false; // TODO
HeldBlock = block; HeldBlock = block;
bool wasPlaced = HeldBlock.Mode == BuildingBlock.BlockMode.Placed;
var oldLocalRot = HeldBlock.Quaternion;
HeldBlock.SetMode(BuildingBlock.BlockMode.NonPhysical); HeldBlock.SetMode(BuildingBlock.BlockMode.NonPhysical);
HeldBlock.Reparent(Hand, true); HeldBlock.Reparent(Hand, true);
HeldBlock.Rotation = Vector3.Zero; if (!wasPlaced)
HeldBlock.Quaternion = new Quaternion(Vector3.Up, RotateAmt * RNG.RandiRange(0, 100));
else
HeldBlock.Quaternion = oldLocalRot;
return true; return true;
} }
} }

View File

@ -80,6 +80,9 @@ namespace Gmtk24 {
} }
GhostBlock.Position = LocalPos * Basis; GhostBlock.Position = LocalPos * Basis;
} }
if (Orbit.HeldBlock != null)
GhostBlock.Rotation = Orbit.HeldBlock.Rotation;
} }
} }