Add GhostBlock
This commit is contained in:
parent
b8613ed60c
commit
8eb56b39e1
@ -54,7 +54,7 @@ size = Vector3(43.3174, 26.5295, 43.4319)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.332064, 1.5426, 3.65156)
|
||||
|
||||
[node name="table" parent="." node_paths=PackedStringArray("TrenchbroomMap") instance=ExtResource("11_7trvw")]
|
||||
transform = Transform3D(-0.0123217, 0, 0.999924, 0, 1, 0, -0.999924, 0, -0.0123217, 2.83695, 0, -4.36558)
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 2.83695, 0, -4.36558)
|
||||
TrenchbroomMap = NodePath("../DemoMap")
|
||||
RelativeScale = 0.005
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://d02cqylu3xwos"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://d02cqylu3xwos"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://diwlyi146eroa" path="res://models/table.fbx" id="1_1soa3"]
|
||||
[ext_resource type="Script" path="res://scripts/Table.cs" id="1_cb7s1"]
|
||||
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="2_1s35y"]
|
||||
[ext_resource type="Material" uid="uid://pu02smf107o8" path="res://textures/building_block_hover.tres" id="3_m64id"]
|
||||
[ext_resource type="Script" path="res://scripts/Orbit.cs" id="4_nyqjn"]
|
||||
[ext_resource type="Material" uid="uid://bfxaaqdjgwv8b" path="res://textures/building_block_ghost.tres" id="4_twdnh"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_iiew7"]
|
||||
size = Vector3(1.26587, 1.10037, 2.3989)
|
||||
@ -24,10 +25,11 @@ collision_mask = 7
|
||||
lock_rotation = true
|
||||
freeze = true
|
||||
script = ExtResource("1_cb7s1")
|
||||
BlockMaterial = ExtResource("2_1s35y")
|
||||
BlockHoverMaterial = ExtResource("3_m64id")
|
||||
SpawnPoint = NodePath("SpawnPoint")
|
||||
BlockMask = 10
|
||||
BlockMaterial = ExtResource("2_1s35y")
|
||||
BlockHoverMaterial = ExtResource("3_m64id")
|
||||
BlockGhostMaterial = ExtResource("4_twdnh")
|
||||
Orbit = NodePath("Orbit")
|
||||
InteractName = "build"
|
||||
|
||||
@ -64,6 +66,30 @@ shape = SubResource("BoxShape3D_5k7xn")
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
|
||||
shape = SubResource("BoxShape3D_3kmm7")
|
||||
|
||||
[node name="TableWalls" type="StaticBody3D" parent="TableWalls"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="Wall1" type="CollisionShape3D" parent="TableWalls/TableWalls"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, 3.66627)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall2" type="CollisionShape3D" parent="TableWalls/TableWalls"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, -3.69933)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall3" type="CollisionShape3D" parent="TableWalls/TableWalls"]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -3.1173, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Wall4" type="CollisionShape3D" parent="TableWalls/TableWalls"]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 3.1173, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Roof" type="CollisionShape3D" parent="TableWalls/TableWalls"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
|
||||
shape = SubResource("BoxShape3D_3kmm7")
|
||||
|
||||
[node name="Orbit" type="Node3D" parent="." node_paths=PackedStringArray("Camera", "Hand")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.12311, 0)
|
||||
script = ExtResource("4_nyqjn")
|
||||
|
@ -12,7 +12,7 @@ namespace Gmtk24 {
|
||||
public float RelativeScale;
|
||||
public uint PhysicalModeLayer;
|
||||
|
||||
public BlockMode Mode { private set; get; } = BlockMode.Physical;
|
||||
public BlockMode Mode = BlockMode.Physical;
|
||||
|
||||
private MeshInstance3D MeshInstance;
|
||||
|
||||
@ -60,6 +60,7 @@ namespace Gmtk24 {
|
||||
HoverMaterialArr[i] = newHoverMat;
|
||||
} else {
|
||||
NormalMaterialArr[i] = Material;
|
||||
HoverMaterialArr[i] = HoverMaterial;
|
||||
}
|
||||
MeshInstance.SetSurfaceOverrideMaterial(i, NormalMaterialArr[i]);
|
||||
}
|
||||
@ -79,7 +80,6 @@ namespace Gmtk24 {
|
||||
}
|
||||
|
||||
public void SetMode(BlockMode mode) {
|
||||
GD.Print(mode);
|
||||
Mode = mode;
|
||||
SetMaterial(false);
|
||||
UpdatePhysics();
|
||||
|
@ -3,6 +3,9 @@ using System;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Orbit : Node3D {
|
||||
[Signal]
|
||||
public delegate void BlockReleaseEventHandler(BuildingBlock block, uint blockReleaseTypeUint);
|
||||
|
||||
[Export(PropertyHint.Range, "0,10,0.1")]
|
||||
public float MaxCameraDistance = 1f;
|
||||
[Export(PropertyHint.Range, "0,10,0.1")]
|
||||
@ -60,21 +63,12 @@ namespace Gmtk24 {
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("release_block")) {
|
||||
HeldBlock.SetMode(BuildingBlock.BlockMode.Physical);
|
||||
HeldBlock.Reparent(GetParent());
|
||||
var normal = Camera.ProjectRayNormal(Camera.GetViewport().GetMousePosition());
|
||||
var direction = normal * 10;
|
||||
|
||||
var res = Util.RaycastFromMouse(Camera, 0b1111);
|
||||
if (res is RaycastResult results) {
|
||||
GD.Print(results.Position);
|
||||
direction = (results.Position - HeldBlock.GlobalPosition + Vector3.Up * 0.5f) * 3;
|
||||
}
|
||||
HeldBlock.ApplyImpulse(direction);
|
||||
|
||||
if (HeldBlock != null) {
|
||||
EmitSignal(SignalName.BlockRelease, HeldBlock, (uint)BlockReleaseType.Throw);
|
||||
HeldBlock = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HoldBlock(BuildingBlock block) {
|
||||
if (HeldBlock != null)
|
||||
@ -87,4 +81,9 @@ namespace Gmtk24 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BlockReleaseType {
|
||||
Throw = 0,
|
||||
Place = 1,
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,26 @@ namespace Gmtk24 {
|
||||
public partial class Table : Interactible {
|
||||
[Export(PropertyHint.NodeType, "FuncGodotMap")]
|
||||
public Node3D TrenchbroomMap;
|
||||
[ExportCategory("SpawnOptions")]
|
||||
[Export(PropertyHint.Range, "0.005,0.1,0.005,or_greater")]
|
||||
public float RelativeScale = 0.05f;
|
||||
[Export]
|
||||
public Node3D SpawnPoint;
|
||||
[Export(PropertyHint.LayersAvoidance)]
|
||||
public uint BlockMask;
|
||||
[ExportCategory("BlockMaterials")]
|
||||
[Export]
|
||||
public ShaderMaterial BlockMaterial;
|
||||
[Export]
|
||||
public ShaderMaterial BlockHoverMaterial;
|
||||
[Export]
|
||||
public Node3D SpawnPoint;
|
||||
[Export(PropertyHint.LayersAvoidance)]
|
||||
public uint BlockMask;
|
||||
public ShaderMaterial BlockGhostMaterial;
|
||||
|
||||
[Export]
|
||||
public Orbit Orbit;
|
||||
|
||||
public BuildingBlock GhostBlock;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready() {
|
||||
Vector3 SpawnPos = Vector3.Zero;
|
||||
@ -27,6 +33,8 @@ namespace Gmtk24 {
|
||||
SpawnPos = SpawnPoint.GlobalPosition - GlobalPosition;
|
||||
|
||||
SpawnBlocks(SpawnPos);
|
||||
|
||||
Orbit.BlockRelease += OnBlockRelease;
|
||||
}
|
||||
|
||||
public void SpawnBlocks(Vector3 position) {
|
||||
@ -56,8 +64,60 @@ namespace Gmtk24 {
|
||||
Orbit.SetEnabled(true);
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
if (GhostBlock != null) {
|
||||
var res = Util.RaycastFromMouse(Orbit.Camera, 0b100);
|
||||
if (res is RaycastResult results) {
|
||||
Vector3 Pos = results.Position - GlobalPosition;
|
||||
GhostBlock.Position = Pos * Basis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBlockPickup(BuildingBlock block) {
|
||||
Orbit.HoldBlock(block);
|
||||
Vector3 LocalPos = Vector3.Zero;
|
||||
GhostBlock = new BuildingBlock() {
|
||||
Base = block.Base,
|
||||
Material = BlockGhostMaterial,
|
||||
PhysicalModeLayer = 0,
|
||||
RelativeScale = RelativeScale,
|
||||
Position = LocalPos,
|
||||
Mode = BuildingBlock.BlockMode.NonPhysical,
|
||||
};
|
||||
AddChild(GhostBlock);
|
||||
}
|
||||
|
||||
public void OnBlockRelease(BuildingBlock block, uint typeUint) {
|
||||
if (GhostBlock != null) {
|
||||
GhostBlock.QueueFree();
|
||||
GhostBlock = null;
|
||||
}
|
||||
|
||||
BlockReleaseType type = (BlockReleaseType)typeUint;
|
||||
switch (type) {
|
||||
case BlockReleaseType.Throw: {
|
||||
|
||||
block.SetMode(BuildingBlock.BlockMode.Physical);
|
||||
block.Reparent(this);
|
||||
var normal = Orbit.Camera.ProjectRayNormal(Orbit.Camera.GetViewport().GetMousePosition());
|
||||
var direction = normal * 10;
|
||||
|
||||
var res = Util.RaycastFromMouse(Orbit.Camera, 0b1111);
|
||||
if (res is RaycastResult results) {
|
||||
direction = (results.Position - block.GlobalPosition + Vector3.Up * 0.5f) * 3;
|
||||
}
|
||||
block.ApplyImpulse(direction);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BlockReleaseType.Place: {
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
13
textures/building_block_ghost.tres
Normal file
13
textures/building_block_ghost.tres
Normal file
@ -0,0 +1,13 @@
|
||||
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bfxaaqdjgwv8b"]
|
||||
|
||||
[ext_resource type="Shader" path="res://textures/building_block.gdshader" id="1_dis1h"]
|
||||
|
||||
[resource]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_dis1h")
|
||||
shader_parameter/albedo = Color(0.276387, 0.574926, 0.813629, 0.54902)
|
||||
shader_parameter/roughness = 0.533
|
||||
shader_parameter/specular = 0.45
|
||||
shader_parameter/metallic = null
|
||||
shader_parameter/uv1_scale = Vector3(1, 1, 1)
|
||||
shader_parameter/uv1_offset = null
|
Loading…
Reference in New Issue
Block a user