new build mechanic
This commit is contained in:
41
Scripts/building_area.gd
Normal file
41
Scripts/building_area.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends StaticBody3D
|
||||
|
||||
@onready var beds = preload("res://Scenes/Prefabs/DoubleBeds.tscn")
|
||||
|
||||
var areas
|
||||
var previewObject: Node3D
|
||||
var is_placed = false
|
||||
func _ready() -> void:
|
||||
areas = get_children()
|
||||
Global.exit_build_mode.connect(_on_exit_build_mode)
|
||||
|
||||
|
||||
func _input_event(camera: Camera3D, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
||||
if event.is_action_pressed("mouse_click") and Global.build_mode:
|
||||
place_object()
|
||||
|
||||
|
||||
|
||||
func _mouse_enter() -> void:
|
||||
if !is_placed and Global.build_mode:
|
||||
show_preview()
|
||||
|
||||
func _mouse_exit() -> void:
|
||||
if !is_placed and Global.build_mode:
|
||||
hide_preview()
|
||||
|
||||
func show_preview():
|
||||
previewObject = beds.instantiate()
|
||||
areas[0].add_child(previewObject)
|
||||
|
||||
func hide_preview():
|
||||
if is_placed != true:
|
||||
if previewObject != null:
|
||||
previewObject.queue_free()
|
||||
|
||||
func place_object():
|
||||
is_placed = true
|
||||
|
||||
|
||||
func _on_exit_build_mode():
|
||||
hide_preview()
|
||||
1
Scripts/building_area.gd.uid
Normal file
1
Scripts/building_area.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bcmd74mxocn7e
|
||||
@@ -4,6 +4,8 @@ extends Camera3D
|
||||
@export var camera_speed: float
|
||||
@export var ownRigidBody: RigidBody3D
|
||||
@export var endZoom: Node3D
|
||||
@export var particlesSystem: GPUParticles3D
|
||||
@export var worldEnvironmentSystem: WorldEnvironment
|
||||
var debugLabel
|
||||
var global_delta
|
||||
var default_pos
|
||||
@@ -11,9 +13,13 @@ var default_pos
|
||||
func _ready() -> void:
|
||||
default_pos = self.position
|
||||
debugLabel = $DebugLabel1
|
||||
particlesSystem.emitting = true
|
||||
var environment = worldEnvironmentSystem.environment
|
||||
environment.fog_enabled = true
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
debugLabel.text = "Mode: " + str(Global.build_mode)
|
||||
global_delta = delta
|
||||
look_at(ownRigidBody.position)
|
||||
self.position.y = -0.1 * pow(self.position.z,2) + 40
|
||||
|
||||
@@ -5,31 +5,10 @@ extends Node3D
|
||||
@export var cartTop: MeshInstance3D
|
||||
@export var mainCamera: Camera3D
|
||||
|
||||
var build_mode = false
|
||||
var previewObject
|
||||
var targetPos
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("hide_top"):
|
||||
cartTop.visible = !cartTop.visible
|
||||
if event.is_action_pressed("enter_build_mode"):
|
||||
build_mode = !build_mode
|
||||
add_preview()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if build_mode:
|
||||
targetPos = mainCamera.getGlobalRayTargetObject()
|
||||
#mainCamera.debugLabel.text = targetPos.collider.name
|
||||
|
||||
if is_instance_valid(targetPos):
|
||||
if targetPos.collider.has_meta("is_building_area"):
|
||||
#if targetPos.collider.is_building_area == true:
|
||||
previewObject.visible = true
|
||||
previewObject.global_position = targetPos.position
|
||||
else:
|
||||
previewObject.visible = false
|
||||
|
||||
|
||||
func add_preview():
|
||||
previewObject = beds.instantiate()
|
||||
get_tree().root.get_child(0).add_child(previewObject)
|
||||
#add_preview()
|
||||
|
||||
17
Scripts/global_script.gd
Normal file
17
Scripts/global_script.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Node3D
|
||||
@export var debugLabel1: Label
|
||||
|
||||
|
||||
signal exit_build_mode
|
||||
|
||||
var build_mode: bool = false
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_released("enter_build_mode"):
|
||||
if build_mode:
|
||||
exit_build_mode.emit()
|
||||
build_mode = false
|
||||
else:
|
||||
build_mode = true
|
||||
|
||||
1
Scripts/global_script.gd.uid
Normal file
1
Scripts/global_script.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://be4romsmai6jd
|
||||
1
Scripts/small_building_area.gd
Normal file
1
Scripts/small_building_area.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends CollisionShape3D
|
||||
1
Scripts/small_building_area.gd.uid
Normal file
1
Scripts/small_building_area.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c3sewowdqkd83
|
||||
Reference in New Issue
Block a user