From 95d9bd342cbede761dd7a5b0c7deda3eb3b1fe7b Mon Sep 17 00:00:00 2001 From: bvanroll Date: Wed, 19 Jun 2024 16:06:18 +0200 Subject: [PATCH] momentum works, now to find out how to impl bounce --- node_3d.tscn | 4 ++-- player_move.gd | 36 +++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/node_3d.tscn b/node_3d.tscn index 97c0a00..2f08375 100644 --- a/node_3d.tscn +++ b/node_3d.tscn @@ -3,10 +3,10 @@ [ext_resource type="Script" path="res://player_move.gd" id="1_3w378"] [sub_resource type="BoxShape3D" id="BoxShape3D_xx3kl"] -size = Vector3(20, 0.1, 20) +size = Vector3(100, 0.1, 100) [sub_resource type="BoxMesh" id="BoxMesh_lwlrc"] -size = Vector3(20, 0.1, 20) +size = Vector3(100, 0.1, 100) [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_fla64"] diff --git a/player_move.gd b/player_move.gd index 1a0ea9c..b60bdff 100644 --- a/player_move.gd +++ b/player_move.gd @@ -2,32 +2,46 @@ extends CharacterBody3D const SPEED = 5.0 -const JUMP_VELOCITY = 10.5 +const AIRSPEED = 8.0 +const MAXSPEED = 8.0 +const JUMP_VELOCITY = 3.5 # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") -var vel = Vector3(0.01,gravity,0.01) func _physics_process(delta): # Add the gravity. - if not is_on_floor(): - velocity.y -= gravity * delta # Handle jump. var jv = JUMP_VELOCITY + abs(velocity.y) - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = jv + #if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + # velocity.y = jv # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") + var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - if direction: - velocity.x = direction.x * SPEED - velocity.z = direction.z * SPEED + + if is_on_floor(): + if direction: + if abs(velocity.x) < MAXSPEED: + velocity.x += direction.x * SPEED *3. * delta + if abs(velocity.z) < MAXSPEED: + velocity.z += direction.z * SPEED *3. * delta + if Input.is_action_pressed("ui_accept"): + velocity.y += jv + velocity.x = move_toward(velocity.x, 0, SPEED * delta) + velocity.z = move_toward(velocity.z, 0, SPEED * delta) + else: - velocity.x = move_toward(velocity.x, 0, SPEED) - velocity.z = move_toward(velocity.z, 0, SPEED) + velocity.y -= gravity * delta + if direction: + velocity.x += direction.x * AIRSPEED *3. * delta + velocity.z += direction.z * AIRSPEED *3. * delta + velocity.x = move_toward(velocity.x, 0, SPEED * (delta/2.)) + velocity.z = move_toward(velocity.z, 0, SPEED * (delta/2.)) + log(1.) move_and_slide()