momentum works, now to find out how to impl bounce

This commit is contained in:
2024-06-19 16:06:18 +02:00
parent 2146b01abd
commit 95d9bd342c
2 changed files with 27 additions and 13 deletions

View File

@@ -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"]

View File

@@ -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 is_on_floor():
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
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()