adds the game
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@onready var objMesh = $MeshInstance3D
|
||||
@onready var objCollision = $CollisionShape3D
|
||||
|
||||
@export_enum("default","wood") var objMaterial = "default"
|
||||
|
||||
@export var autoGlue:bool = false ## Toggles wether or not it sticks to nearby objects on spawn.
|
||||
|
||||
@export var properties:Dictionary = { ## The properties the object will have upon spawning.
|
||||
"size": Vector3(0.1,0.1,0.1),
|
||||
"modifiers": {
|
||||
"magnetic": false,
|
||||
},
|
||||
}
|
||||
|
||||
@export var gluedTo:Array[NodePath] ## Nodes that this object will be glued to (press "Add Element" and assign the node.)
|
||||
|
||||
var materials:Dictionary = {
|
||||
"default":{"weight":1,"material":null,"modifiers":[]},
|
||||
"wood":{"weight":5,"material":"res://assets/wood.tres","modifiers":[]}
|
||||
}
|
||||
|
||||
func _ready():
|
||||
setBasics()
|
||||
|
||||
#sets the basic weight, shape, and material of the object
|
||||
func setBasics():
|
||||
var mat = materials[objMaterial]
|
||||
|
||||
objMesh.mesh.size = properties["size"]
|
||||
objCollision.shape.size = properties["size"]
|
||||
$glueBox/CollisionShape3D.shape.size = properties["size"] + Vector3(0.02,0.02,0.02)
|
||||
if mat["material"] != null:
|
||||
var i = load(mat["material"])
|
||||
objMesh.mesh.material = i
|
||||
|
||||
mass = mat["weight"] * (properties["size"].x + properties["size"].y + properties["size"].z)
|
||||
@@ -0,0 +1 @@
|
||||
uid://df35nkh3byxis
|
||||
@@ -0,0 +1,32 @@
|
||||
extends XRController3D
|
||||
|
||||
var grabTarget: NodePath = NodePath()
|
||||
var grabbing = false
|
||||
@export var physicsHand: RigidBody3D
|
||||
@onready var physicsPath: NodePath = physicsHand.get_path()
|
||||
@onready var hinge = physicsHand.get_node("HingeJoint3D")
|
||||
|
||||
func _on_input_float_changed(action_name: String, value: float) -> void:
|
||||
if action_name == "grip":
|
||||
if value >= 0.5:
|
||||
grab(true)
|
||||
else:
|
||||
grab(false)
|
||||
|
||||
func grab(grabORrelease: bool):
|
||||
if grabORrelease == true and not grabbing:
|
||||
grabbing = true
|
||||
if grabTarget != NodePath():
|
||||
hinge.node_a = physicsPath
|
||||
hinge.node_b = grabTarget
|
||||
if grabORrelease == false:
|
||||
grabbing = false
|
||||
hinge.node_a = NodePath()
|
||||
hinge.node_b = NodePath()
|
||||
|
||||
|
||||
func _rigid_body_entered(body: Node) -> void:
|
||||
grabTarget = body.get_path()
|
||||
|
||||
func _rigid_body_exited(body: Node) -> void:
|
||||
grabTarget = NodePath()
|
||||
@@ -0,0 +1 @@
|
||||
uid://clfxgaxhlvxxo
|
||||
@@ -0,0 +1,22 @@
|
||||
extends XRController3D
|
||||
|
||||
var grabTarget: NodePath = NodePath()
|
||||
var grabbing = false
|
||||
@export var physicsHand: RigidBody3D
|
||||
|
||||
@onready var hinge = physicsHand.get_node("HingeJoint3D")
|
||||
|
||||
func _on_input_float_changed(action_name: String, value: float) -> void:
|
||||
if action_name == "grip":
|
||||
if value >= 0.5:
|
||||
grab(true)
|
||||
else:
|
||||
grab(false)
|
||||
|
||||
|
||||
|
||||
func _rigid_body_entered(body: Node) -> void:
|
||||
grabTarget = body.get_path()
|
||||
|
||||
func _rigid_body_exited(body: Node) -> void:
|
||||
grabTarget = NodePath()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bamf7n1e430xe
|
||||
@@ -0,0 +1,16 @@
|
||||
extends MultiplayerSpawner
|
||||
|
||||
@export var network_player: PackedScene
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
multiplayer.peer_connected.connect(spawnPlayer)
|
||||
|
||||
|
||||
func spawnPlayer(id: int) -> void:
|
||||
if not multiplayer.is_server(): return
|
||||
|
||||
var player: Node = network_player.instantiate()
|
||||
player.name = str(id)
|
||||
|
||||
get_node(spawn_path).call_deferred("add_child", player)
|
||||
@@ -0,0 +1 @@
|
||||
uid://iishy6cydfps
|
||||
@@ -0,0 +1,19 @@
|
||||
extends Control
|
||||
|
||||
var player
|
||||
|
||||
func _ready():
|
||||
print($/root/main/world/menuPlayer)
|
||||
player = $/root/main/world/menuPlayer
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
NetworkHandler.startServer()
|
||||
player.queue_free()
|
||||
|
||||
|
||||
func _on_button_2_pressed() -> void:
|
||||
var IPAdress = "localhost"
|
||||
if $VBoxContainer/LineEdit.text != "":
|
||||
IPAdress = $VBoxContainer/LineEdit.text
|
||||
player.queue_free()
|
||||
NetworkHandler.startClient(IPAdress)
|
||||
@@ -0,0 +1 @@
|
||||
uid://brb6tvcl1busf
|
||||
@@ -0,0 +1,22 @@
|
||||
extends Node
|
||||
|
||||
var IP_ADDRESS: String = "localhost"
|
||||
const PORT: int = 42069
|
||||
|
||||
var peer: ENetMultiplayerPeer
|
||||
|
||||
func startServer() -> void:
|
||||
peer = ENetMultiplayerPeer.new()
|
||||
peer.create_server(PORT)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
print("server started")
|
||||
$/root/main/world/MultiplayerSpawner.spawnPlayer(1)
|
||||
|
||||
|
||||
func startClient(IP_target) -> void:
|
||||
if IP_target != "":
|
||||
IP_ADDRESS = IP_target
|
||||
peer = ENetMultiplayerPeer.new()
|
||||
peer.create_client(IP_ADDRESS, PORT)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
print("client started")
|
||||
@@ -0,0 +1 @@
|
||||
uid://cko5qfasmrl45
|
||||
@@ -0,0 +1,11 @@
|
||||
extends Node3D
|
||||
|
||||
@export var debug = false
|
||||
|
||||
func _enter_tree() -> void:
|
||||
if !debug:
|
||||
print(name, " entered")
|
||||
set_multiplayer_authority(name.to_int())
|
||||
if !is_multiplayer_authority():
|
||||
$XROrigin3D/XRCamera3D.queue_free()
|
||||
$XROrigin3D.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
@@ -0,0 +1 @@
|
||||
uid://csbuxf0o41r55
|
||||
@@ -0,0 +1,11 @@
|
||||
extends StaticBody3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print(get_path())
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
self.position.x += 0.01
|
||||
@@ -0,0 +1 @@
|
||||
uid://b7sj2fsybkjwp
|
||||
@@ -0,0 +1,40 @@
|
||||
extends XROrigin3D
|
||||
|
||||
|
||||
@onready var _hand_rigidbody_left : RigidBody3D = $leftHand/leftRigid
|
||||
@onready var _hand_rigidbody_right : RigidBody3D = $rightHand/rightRigid
|
||||
|
||||
@onready var _hand_contr_left : Node3D = $leftHand
|
||||
@onready var _hand_contr_right : Node3D = $rightHand
|
||||
|
||||
func _ready() -> void:
|
||||
_hand_rigidbody_left.top_level = true
|
||||
_hand_rigidbody_right.top_level = true
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
$MeshInstance3D.position = $XRCamera3D.position
|
||||
if self.position.y <= -10:
|
||||
self.position = Vector3(0,0,0)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_move_hand_rigidbody_to_contr(_hand_rigidbody_left, _hand_contr_left)
|
||||
_move_hand_rigidbody_to_contr(_hand_rigidbody_right, _hand_contr_right)
|
||||
|
||||
|
||||
func _move_hand_rigidbody_to_contr(hand_rigidbody: RigidBody3D, hand_contr: Node3D) -> void:
|
||||
# 1 force hand rigidbody to hand contr
|
||||
var move_delta : Vector3 = hand_contr.global_position - hand_rigidbody.global_position
|
||||
|
||||
var coef_force := 300.0
|
||||
hand_rigidbody.apply_central_force(move_delta * coef_force)
|
||||
|
||||
# 2 torque hand rigidbody to hand contr
|
||||
var quat_hand_rigidbody : Quaternion = hand_rigidbody.global_transform.basis.get_rotation_quaternion()
|
||||
var quat_hand_contr : Quaternion = hand_contr.global_transform.basis.get_rotation_quaternion()
|
||||
var quat_delta : Quaternion = quat_hand_contr * (quat_hand_rigidbody.inverse())
|
||||
var rotation_delta : Vector3 = Vector3(quat_delta.x, quat_delta.y, quat_delta.z) * quat_delta.w
|
||||
|
||||
var coef_torque := 6.0
|
||||
hand_rigidbody.apply_torque(rotation_delta * coef_torque)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ch7s411vwan10
|
||||
Reference in New Issue
Block a user