ladder working
This commit is contained in:
@@ -1,15 +1,8 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://cgo4qyul7ix5p"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://cgo4qyul7ix5p"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ladder.gd" id="1_8cik3"]
|
||||
[ext_resource type="Texture2D" uid="uid://y7skmb07dvc7" path="res://assets/Models/latter1.albedo.png" id="1_sa5qp"]
|
||||
[ext_resource type="Texture2D" uid="uid://3imms57ifxed" path="res://assets/Models/ladder1.normal.png" id="2_sljvk"]
|
||||
|
||||
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_a6qo5"]
|
||||
points = PackedVector3Array(-0.314334, -0.509434, -0.0955157, 3.70923, 0.496458, 0.0930522, 3.70923, 0.496458, -0.0955157, -0.314334, 0.496458, 0.0930522, 3.70923, -0.509434, 0.0930522, 3.70923, -0.509434, -0.0955157, -0.314334, 0.496458, -0.0955157, -0.314334, -0.509434, 0.0930522)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_gxu3i"]
|
||||
size = Vector3(1, 4.30298, 1.6582)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_oksqm"]
|
||||
resource_name = "ladder1"
|
||||
cull_mode = 2
|
||||
@@ -53,25 +46,16 @@ _surfaces = [{
|
||||
blend_shape_mode = 0
|
||||
shadow_mesh = SubResource("ArrayMesh_4hcxi")
|
||||
|
||||
[node name="Ladder" type="Node3D"]
|
||||
script = ExtResource("1_8cik3")
|
||||
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_wmqg7"]
|
||||
points = PackedVector3Array(-0.314334, -0.509434, -0.0955157, 3.70923, 0.496458, 0.0930522, 3.70923, 0.496458, -0.0955157, -0.314334, 0.496458, 0.0930522, 3.70923, -0.509434, 0.0930522, 3.70923, -0.509434, -0.0955157, -0.314334, 0.496458, -0.0955157, -0.314334, -0.509434, 0.0930522)
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"]
|
||||
transform = Transform3D(3.57628e-07, 1, 7.54979e-08, 1, -3.57628e-07, -7.54979e-08, -7.54979e-08, 7.54979e-08, -1, 0, 0, 0)
|
||||
shape = SubResource("ConvexPolygonShape3D_a6qo5")
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.70557, 0.329102)
|
||||
shape = SubResource("BoxShape3D_gxu3i")
|
||||
[node name="Ladder" type="StaticBody3D"]
|
||||
|
||||
[node name="Ladder1" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(3.57628e-07, 1, 7.54979e-08, 1, -3.57628e-07, -7.54979e-08, -7.54979e-08, 7.54979e-08, -1, 0, 0, 0)
|
||||
mesh = SubResource("ArrayMesh_meake")
|
||||
skeleton = NodePath("")
|
||||
|
||||
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]
|
||||
[connection signal="body_exited" from="Area3D" to="." method="_on_area_3d_body_exited"]
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(3.57628e-07, 1, 7.54979e-08, 1, -3.57628e-07, -7.54979e-08, -7.54979e-08, 7.54979e-08, -1, 0, 0, 0)
|
||||
shape = SubResource("ConvexPolygonShape3D_wmqg7")
|
||||
|
||||
16
assets/ladder_collision_check.tscn
Normal file
16
assets/ladder_collision_check.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cdpxctwwi12j"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ladder.gd" id="1_ugi45"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_gxu3i"]
|
||||
size = Vector3(1, 8.23889, 1.6582)
|
||||
|
||||
[node name="LadderCollisionCheck" type="Area3D"]
|
||||
script = ExtResource("1_ugi45")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.67353, 0.329102)
|
||||
shape = SubResource("BoxShape3D_gxu3i")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||
File diff suppressed because one or more lines are too long
@@ -1,24 +1,25 @@
|
||||
extends Node3D
|
||||
extends Area3D
|
||||
|
||||
var is_climbing = false
|
||||
var ladder_center
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
ladder_center = self.global_position
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_3d_body_entered(body):
|
||||
func _on_body_entered(body):
|
||||
if body.is_in_group("player"):
|
||||
is_climbing = true
|
||||
body.lader_collide(is_climbing)
|
||||
body.is_climbing = true
|
||||
body.ladder_center = ladder_center
|
||||
|
||||
|
||||
func _on_area_3d_body_exited(body):
|
||||
|
||||
func _on_body_exited(body):
|
||||
if body.is_in_group("player"):
|
||||
is_climbing = false
|
||||
body.lader_collide(is_climbing)
|
||||
body.is_climbing = false
|
||||
body.gravity = body.default_gravity
|
||||
body.ladder_center = null
|
||||
|
||||
@@ -4,6 +4,8 @@ extends CharacterBody3D
|
||||
var speed
|
||||
var double_jump = true
|
||||
var gravity = 9.8
|
||||
var is_climbing = false
|
||||
var ladder_center
|
||||
var default_gravity = gravity
|
||||
var mouse_input : Vector2
|
||||
|
||||
@@ -101,9 +103,9 @@ func _physics_process(delta):
|
||||
double_jump = true
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor() and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true:
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
double_jump = false
|
||||
|
||||
@@ -116,13 +118,21 @@ func _physics_process(delta):
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if is_on_floor():
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
elif is_climbing:
|
||||
gravity = 0.0
|
||||
if direction:
|
||||
velocity.y = -direction.z * speed * .75
|
||||
velocity.x = direction.x * speed * .3
|
||||
else:
|
||||
velocity.y = lerp(velocity.y, -direction.z * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
@@ -278,11 +288,9 @@ func _on_pick_up_detection_body_entered(body):
|
||||
level_control.gun_spawn(weapon_id)
|
||||
|
||||
|
||||
func lader_collide(is_climbing):
|
||||
func ladder_collide(is_climbing):
|
||||
|
||||
if is_climbing == true:
|
||||
if Input.is_action_pressed("move_up"):
|
||||
velocity.y += 5
|
||||
gravity = 0.0
|
||||
else:
|
||||
gravity = default_gravity
|
||||
@@ -315,6 +323,7 @@ func weapon_recoil(delta):
|
||||
var recoil_to = camera.rotation.x + gun.recoil_amount
|
||||
camera.rotation.x = clamp(lerp(camera.rotation.x,recoil_to, .05), deg_to_rad(-90), deg_to_rad(85))
|
||||
|
||||
|
||||
func die():
|
||||
Engine.time_scale = .05
|
||||
var deadmsg = dead_announce.instantiate()
|
||||
|
||||
Reference in New Issue
Block a user