Add rotations
This commit is contained in:
parent
8bac5dbe77
commit
3f91453a1b
@ -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)
|
||||
]
|
||||
}
|
||||
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]
|
||||
|
||||
|
@ -17,6 +17,8 @@ namespace Gmtk24 {
|
||||
public Node3D Hand;
|
||||
[Export]
|
||||
public BuildingBlock HeldBlock { private set; get; }
|
||||
[Export]
|
||||
public float RotateAmt = (float)(Math.PI / 12);
|
||||
|
||||
[Export]
|
||||
public bool IsEnabled { private set; get; } = false;
|
||||
@ -24,6 +26,8 @@ namespace Gmtk24 {
|
||||
private float CurrentYaw = 0;
|
||||
private float CurrentPitch = 0;
|
||||
|
||||
private RandomNumberGenerator RNG = new RandomNumberGenerator();
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready() {
|
||||
}
|
||||
@ -72,6 +76,13 @@ namespace Gmtk24 {
|
||||
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) {
|
||||
@ -79,9 +90,15 @@ namespace Gmtk24 {
|
||||
return false; // TODO
|
||||
|
||||
HeldBlock = block;
|
||||
bool wasPlaced = HeldBlock.Mode == BuildingBlock.BlockMode.Placed;
|
||||
var oldLocalRot = HeldBlock.Quaternion;
|
||||
HeldBlock.SetMode(BuildingBlock.BlockMode.NonPhysical);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,9 @@ namespace Gmtk24 {
|
||||
}
|
||||
GhostBlock.Position = LocalPos * Basis;
|
||||
}
|
||||
|
||||
if (Orbit.HeldBlock != null)
|
||||
GhostBlock.Rotation = Orbit.HeldBlock.Rotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user