Quake->Xonotic physics

Memes
This commit is contained in:
Thomas Muller 2023-10-02 00:36:31 -04:00
parent cbd46b7e26
commit d99d264352
3 changed files with 47 additions and 19 deletions

View file

@ -11,7 +11,7 @@ func _process(delta):
var v = $Player.velocity
var hvel = sqrt(v.x ** 2 + v.z ** 2)
var vvel = v.y
$Speed.text = 'Speed: %6.2f, %6.2f' % [hvel, vvel]
$Speed.text = 'Speed: %6.2f, %6.2f' % [hvel * 16, vvel * 16]
func _input(event: InputEvent):

View file

@ -3,16 +3,19 @@ extends CharacterBody3D
# Member variables
const QUAKE = 0.0625
const g = -800 * QUAKE
const MAX_SPEED = 2000 * QUAKE
const MAX_SPEED = 320 * QUAKE
const MAX_AIR_SPEED = 30 * QUAKE
const FRICTION = 4# * QUAKE
const STOP_SPEED = 100 * QUAKE
const ACCEL= 10# * QUAKE
const ACCEL = 15# * QUAKE
const AIR_ACCEL = 2# * QUAKE
const FORWARD_SPEED = 200 * QUAKE
const SIDE_SPEED = 350 * QUAKE
const UP_SPEED = 270 * QUAKE
const JUMP_SPEED = 270 * QUAKE
# const DEACCEL= 8
# const MAX_SLOPE_ANGLE = 30
# const MAX_SLOPE_ANGLE = 30https://www.youtube.com/watch?v=v3zT3Z5apaM
@onready
var camera = $CSGMesh3D/Camera3D
@ -40,8 +43,8 @@ func _physics_process(delta):
smove += -SIDE_SPEED
if Input.is_action_pressed("move_right"):
smove += SIDE_SPEED
if Input.is_action_pressed("jump"):
upmove += UP_SPEED
#if Input.is_action_pressed("up"):
# upmove += UP_SPEED
if Input.is_action_pressed("run"):
fmove *= 2.0
smove *= 2.0
@ -54,8 +57,6 @@ func _physics_process(delta):
if _noclip:
wishvel.y += upmove
# else:
# wishvel.y = upmove
var wishdir = wishvel.normalized()
var wishspeed = wishvel.length()
@ -64,8 +65,9 @@ func _physics_process(delta):
wishvel *= MAX_SPEED / wishspeed
wishspeed = MAX_SPEED
if is_on_floor():
velocity.y += upmove
if Input.is_action_pressed("jump") and is_on_floor():
velocity.y += JUMP_SPEED
var vel = velocity
if _noclip:
vel = wishvel
@ -73,7 +75,7 @@ func _physics_process(delta):
vel = _apply_friction(vel, delta)
vel = _apply_accel(vel, wishdir, wishspeed, delta)
else:
vel = _apply_air_accel(vel, wishvel, wishspeed, delta)
vel = _apply_air_accel(vel, wishvel, delta)
if not _noclip:
vel.y += g * delta
@ -100,7 +102,7 @@ func _apply_friction(vel: Vector3, delta: float):
if newspeed < 0.0:
newspeed = 0.0
else:
newspeed /= speed
return vel * newspeed
@ -117,19 +119,19 @@ func _apply_accel(vel: Vector3, wishdir: Vector3, wishspeed: float, delta: float
return vel + accelspeed * wishdir
func _apply_air_accel(vel: Vector3, wishvel: Vector3, wishspeed: float, delta: float):
func _apply_air_accel(vel: Vector3, wishvel: Vector3, delta: float):
var wishveloc = wishvel.normalized()
var wishspd = wishvel.length()
if wishspd > 30 * QUAKE:
wishspd = 30 * QUAKE
if wishspd > MAX_AIR_SPEED:
wishspd = MAX_AIR_SPEED
var currentspeed = vel.dot(wishveloc)
var addspeed = wishspd - currentspeed
if addspeed <= 0:
return vel
var accelspeed = ACCEL * wishspeed * delta
var accelspeed = AIR_ACCEL * wishspd * delta
if accelspeed > addspeed:
accelspeed = addspeed

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=12 format=3 uid="uid://cv8621s5oukrb"]
[gd_scene load_steps=13 format=3 uid="uid://cv8621s5oukrb"]
[ext_resource type="PackedScene" uid="uid://dyyf1q12dchhq" path="res://Player.tscn" id="2_jba6q"]
[ext_resource type="ArrayMesh" uid="uid://bqnoaomgwec3w" path="res://assets/maps/mapentities.obj" id="5_wn745"]
[ext_resource type="Script" path="res://KeyOverlay.gd" id="6_crgb3"]
[ext_resource type="PackedScene" uid="uid://bp1fooevcl4lk" path="res://devworld.tscn" id="7_1im6f"]
[ext_resource type="Script" path="res://Debug.gd" id="7_2k2sn"]
[ext_resource type="Texture2D" uid="uid://dast4ubkinjb5" path="res://assets/textures/zombietextures_funny/kreb.png" id="7_f82yj"]
[ext_resource type="PackedScene" uid="uid://dnk6bedcy6x6m" path="res://hazardcourse.tscn" id="8_t5ilw"]
[sub_resource type="SystemFont" id="SystemFont_4krkk"]
@ -22,6 +23,10 @@ font_names = PackedStringArray("Monospace")
[sub_resource type="LabelSettings" id="LabelSettings_f35h2"]
font = SubResource("SystemFont_4l16k")
[sub_resource type="Environment" id="Environment_4rf1u"]
ambient_light_source = 1
reflected_light_source = 1
[node name="Root" type="Node"]
script = ExtResource("7_2k2sn")
@ -33,7 +38,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 18.9032, 0)
light_color = Color(1, 0.862745, 0.721569, 1)
light_energy = 16.0
light_size = 400.0
omni_range = 99.7884
shadow_enabled = true
omni_range = 181.439
[node name="Mapentities" type="MeshInstance3D" parent="."]
transform = Transform3D(0.039, 0, 0, 0, -1.70474e-09, 0.039, 0, -0.039, -1.70474e-09, 0, 0, 0)
@ -61,3 +67,23 @@ offset_right = 113.0
offset_bottom = 136.0
text = "SPEED"
label_settings = SubResource("LabelSettings_f35h2")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_4rf1u")
[node name="SpotLight3D" type="SpotLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -5.12, 12.1948, -30.2711)
light_energy = 500.0
light_projector = ExtResource("7_f82yj")
shadow_enabled = true
spot_range = 52.48
spot_angle = 26.8834
[node name="SpotLight3D" type="SpotLight3D" parent="SpotLight3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0.0400009, 0)
light_energy = 500.0
light_projector = ExtResource("7_f82yj")
light_negative = true
shadow_enabled = true
spot_range = 52.48
spot_angle = 26.8834