-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from dsg-jam/player-path
Player path & movement
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://bxhfa4fltovbh"] | ||
|
||
[ext_resource type="Script" path="res://scripts/draw_path.gd" id="1_s6kjp"] | ||
|
||
[sub_resource type="Curve3D" id="Curve3D_kfjlp"] | ||
|
||
[sub_resource type="BoxMesh" id="BoxMesh_wrw54"] | ||
size = Vector3(0.1, 0.1, 0.1) | ||
|
||
[sub_resource type="SphereShape3D" id="SphereShape3D_74w4j"] | ||
radius = 0.1 | ||
|
||
[node name="PlayerController" type="Node3D"] | ||
script = ExtResource("1_s6kjp") | ||
|
||
[node name="PlayerPath" type="Path3D" parent="."] | ||
curve = SubResource("Curve3D_kfjlp") | ||
|
||
[node name="PlayerPathFollow" type="PathFollow3D" parent="PlayerPath"] | ||
transform = Transform3D(0.707105, 0, -0.707105, 0, 1, 0, 0.707105, 0, 0.707105, 0, 0, 0) | ||
|
||
[node name="Player" type="MeshInstance3D" parent="PlayerPath/PlayerPathFollow"] | ||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0) | ||
mesh = SubResource("BoxMesh_wrw54") | ||
skeleton = NodePath("../../..") | ||
|
||
[node name="Area3D" type="Area3D" parent="PlayerPath/PlayerPathFollow/Player"] | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerPath/PlayerPathFollow/Player/Area3D"] | ||
shape = SubResource("SphereShape3D_74w4j") | ||
|
||
[node name="CSGPolygon3D" type="CSGPolygon3D" parent="."] | ||
polygon = PackedVector2Array(0, 0, 0, 0.01, 0.01, 0.01, 0.01, 0) | ||
mode = 2 | ||
path_node = NodePath("../PlayerPath") | ||
path_interval_type = 0 | ||
path_interval = 0.03 | ||
path_simplify_angle = 0.0 | ||
path_rotation = 1 | ||
path_local = false | ||
path_continuous_u = false | ||
path_u_distance = 1.0 | ||
path_joined = false | ||
|
||
[connection signal="input_event" from="PlayerPath/PlayerPathFollow/Player/Area3D" to="." method="_on_area_3d_input_event"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://b570nnkcavtyv"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://bxhfa4fltovbh" path="res://prefabs/player.tscn" id="1_n46cj"] | ||
|
||
[node name="PlayerMovementTest" type="Node3D"] | ||
|
||
[node name="Camera3D" type="Camera3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1, 0) | ||
|
||
[node name="Player" parent="." instance=ExtResource("1_n46cj")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
extends Node3D | ||
|
||
@onready var player_path = $PlayerPath | ||
@onready var player_follow = $PlayerPath/PlayerPathFollow | ||
@onready var player = $PlayerPath/PlayerPathFollow/Player | ||
|
||
var path_draw_ongoing: bool = false | ||
var temp_curve: Curve3D = Curve3D.new() | ||
var latest_point: Vector3 = Vector3() | ||
var in_free_move: bool = true | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready() -> void: | ||
player_follow.loop = false | ||
|
||
func _physics_process(delta): | ||
player_follow.progress += delta * 0.2 | ||
if Input.is_action_just_released("click"): | ||
path_draw_ongoing = false | ||
if temp_curve.point_count <= 0: | ||
return | ||
var last_point = temp_curve.get_point_position(temp_curve.get_point_count() - 1) | ||
var second_last_point = temp_curve.get_point_position(temp_curve.get_point_count() - 2) | ||
var direction = (last_point - second_last_point).normalized() | ||
temp_curve.add_point(last_point + direction * 100) | ||
player_path.curve = temp_curve | ||
|
||
if path_draw_ongoing: | ||
mouse_path() | ||
|
||
|
||
func mouse_path(): | ||
var pos = get_viewport().get_mouse_position() | ||
var cam = get_tree().root.get_camera_3d() | ||
pos = cam.project_position(pos, 1.0) | ||
latest_point = pos | ||
var last_point: Vector3 = player.global_position | ||
if temp_curve.point_count > 0: | ||
last_point = temp_curve.get_point_position(temp_curve.point_count-1) | ||
|
||
if last_point.distance_to(latest_point) > 0.025: | ||
temp_curve.add_point(pos) | ||
|
||
|
||
func _on_area_3d_input_event(_camera: Node, event: InputEvent, _event_position: Vector3, _normal: Vector3, _shape_idx: int) -> void: | ||
if event.is_action_pressed("click"): | ||
player_follow.progress = 0 | ||
temp_curve.clear_points() | ||
path_draw_ongoing = true |