Browse Source

Fix wallriding - Add leap, forgiveness

While on wall, if you press jump, you leap up and away from the wall

If you do so immediately after leaving the wall (<tolerance=.150s), it
still works
master
Luna 7 years ago
parent
commit
033ab83e4e
5 changed files with 248 additions and 27 deletions
  1. BIN
      assets/DejaVuSansMono.ttf
  2. +6
    -2
      scenes/player.tscn
  3. +211
    -2
      scenes/world.tscn
  4. +18
    -11
      scripts/heroes/0.gd
  5. +13
    -12
      scripts/player.gd

BIN
assets/DejaVuSansMono.ttf View File


+ 6
- 2
scenes/player.tscn View File

@ -20,7 +20,9 @@ radial_segments = 64
rings = 8
_sections_unfolded = [ "Resource" ]
[node name="RigidBody" type="KinematicBody" index="0"]
[node name="RigidBody" type="KinematicBody" index="0" groups=[
"player",
]]
input_ray_pickable = true
input_capture_on_drag = false
@ -34,7 +36,7 @@ axis_lock_angular_y = false
axis_lock_angular_z = false
collision/safe_margin = 0.001
script = ExtResource( 1 )
_sections_unfolded = [ "Angular", "Collision", "Linear", "Transform", "Visibility" ]
_sections_unfolded = [ "Angular", "Axis Lock", "Collision", "Linear", "Pause", "Transform", "Visibility", "collision" ]
[node name="Body" type="CollisionShape" parent="." index="0"]
@ -95,6 +97,8 @@ mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "+"
align = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1


+ 211
- 2
scenes/world.tscn
File diff suppressed because it is too large
View File


+ 18
- 11
scripts/heroes/0.gd View File

@ -1,7 +1,13 @@
extends "res://scripts/player.gd"
const wallride_speed = 0.5
const wallride_speed = 0
const wallride_speed_necessary = 15
const wallride_leap_height = 10
const wallride_leap_side = 10
var since_on_wall = 0
var last_wall_normal = Vector3()
var wallride_forgiveness = .150
func control_player(delta):
wallride(delta)
@ -9,15 +15,16 @@ func control_player(delta):
func wallride(delta):
# If our feet aren't touching, but we are colliding, we are wall-riding
if is_on_wall() and velocity.length() > wallride_speed_necessary:
if is_on_wall() and not is_on_floor() and velocity.length() > wallride_speed_necessary:
since_on_wall = 0
last_wall_normal = get_slide_collision(0).normal
else:
since_on_wall += delta
if since_on_wall < wallride_forgiveness:
var aim = get_node("Yaw").get_global_transform().basis
var direction = Vector3()
if Input.is_action_pressed("move_forwards"):
direction -= aim[2]
if Input.is_action_pressed("move_backwards"):
direction += aim[2]
velocity += direction * wallride_speed
# Add zero gravity
velocity.y = -gravity # So it's undone in super
else:
pass
# We need to return to falling (we aren't riding anymore)
# Allow jumping (for wall hopping!)
if Input.is_action_just_pressed("jump"):
velocity.y += wallride_leap_height
velocity += wallride_leap_side * last_wall_normal

+ 13
- 12
scripts/player.gd View File

@ -8,9 +8,7 @@ var view_sensitivity = 0.25
var yaw = 0
var pitch = 0
const air_accel = 0.02
var gravity = -1
var gravity = -.8
var velocity = Vector3()
slave var slave_tf = Basis()
slave var slave_vel = Vector3()
@ -20,11 +18,14 @@ var timer = 0
# Walking speed and jumping height are defined later.
var walk_speed = 3
var jump_speed = 15
const air_accel = .5
var health = 100
var stamina = 10000
var ray_length = 10
var debug_node
func _ready():
set_process_input(true)
@ -32,21 +33,20 @@ func _ready():
# Capture mouse once game is started:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
#set_physics_process(true)
get_node("Crosshair").set_text("+")
debug_node = get_node("/root/world/Debug")
if is_network_master():
get_node("Yaw/Camera").make_current()
func _input(event):
if is_network_master():
if event is InputEventMouseMotion:
yaw = fmod(yaw - event.relative.x * view_sensitivity, 360)
pitch = max(min(pitch - event.relative.y * view_sensitivity, 85), -85)
get_node("Yaw").set_rotation(Vector3(0, deg2rad(yaw), 0))
get_node("Yaw/Camera").set_rotation(Vector3(deg2rad(pitch), 0, 0))
# Toggle mouse capture:
if Input.is_action_pressed("toggle_mouse_capture"):
if (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
@ -55,7 +55,7 @@ func _input(event):
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
view_sensitivity = 0.25
# Quit the game:
if Input.is_action_pressed("quit"):
quit()
@ -86,8 +86,7 @@ func control_player(delta):
direction += aim[0]
direction = direction.normalized()
var ray = get_node("Ray")
var friction
if is_on_floor():
@ -108,7 +107,9 @@ func control_player(delta):
velocity.y += gravity
velocity += direction * air_accel
move_and_slide(velocity, Vector3(0, 1, 0))
debug_node.set_text("%8.f,%8.f,%8.f" % [velocity.x, velocity.y, velocity.z])
velocity = move_and_slide(velocity, Vector3(0, 1, 0))
func _exit_scene():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)


Loading…
Cancel
Save