OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / bounce_trace.gd

79 lines · gd ref:
extends Node3D
## Per-frame trace of a downhill run, to see WHAT leaves the floor and when.
## slope_climb_gate says grounded % goes 100/26.7/100/37.3/95.3/41.3 across
## 0/5/10/15/18/20 degrees downhill -- scattered, not a threshold. This dumps the
## frames so the pattern can be read instead of guessed at.
##
##   HTPS_SLOPE=20 "$HYPER_TPS_GODOT" --headless res://scenes/test/bounce_trace.tscn

const SETTLE := 90
const TRACE := 90

var _player: CharacterBody3D = null
var _ground: StaticBody3D = null
var _frames := 0
var _slope := 20.0
var _done := false


func _ready() -> void:
	process_priority = 100
	if OS.has_environment("HTPS_SLOPE"):
		_slope = float(OS.get_environment("HTPS_SLOPE"))
	var s: float = tan(deg_to_rad(_slope))
	_ground = StaticBody3D.new()
	var cs := CollisionShape3D.new()
	var f := PackedVector3Array()
	var i := 0
	while i < 280:
		var j := 0
		while j < 40:
			var x0 := float(i) * 1.5 - 210.0
			var z0 := float(j) * 1.5 - 30.0
			var x1 := x0 + 1.5
			var z1 := z0 + 1.5
			f.push_back(Vector3(x0, x0 * s, z0)); f.push_back(Vector3(x1, x1 * s, z1)); f.push_back(Vector3(x0, x0 * s, z1))
			f.push_back(Vector3(x0, x0 * s, z0)); f.push_back(Vector3(x1, x1 * s, z0)); f.push_back(Vector3(x1, x1 * s, z1))
			j += 1
		i += 1
	var tri := ConcavePolygonShape3D.new()
	tri.set_faces(f)
	cs.shape = tri
	_ground.add_child(cs)
	add_child(_ground)

	var scene: PackedScene = load("res://scenes/player/player_procedural.tscn")
	_player = scene.instantiate()
	add_child(_player)
	_player.global_position = Vector3(0.0, 0.6, 0.0)
	_player.camera_head.global_transform = Transform3D(Basis.IDENTITY, Vector3.ZERO)
	if OS.has_environment("HTPS_CS"):
		_player.floor_constant_speed = OS.get_environment("HTPS_CS") == "1"
	print("slope %.0f deg, running DOWNHILL (-X). snap=%.3f constant_speed=%s max_angle=%.1f deg"
			% [_slope, _player.floor_snap_length, str(_player.floor_constant_speed),
			   rad_to_deg(_player.floor_max_angle)])
	print("")
	print("  f  floor  state   vel.x    vel.y    pos.x     pos.y   ground_y     gap   floor_normal.y")
	print("-----------------------------------------------------------------------------------------")


func _physics_process(_d: float) -> void:
	if _done or _player == null:
		return
	_player.input_sync.input_direction = Vector2(-1.0, 0.0)
	_frames += 1
	if _frames <= SETTLE:
		return
	if _frames > SETTLE + TRACE:
		_done = true
		get_tree().quit(0)
		return
	var p: Vector3 = _player.global_position
	var gy: float = p.x * tan(deg_to_rad(_slope))
	var n: Vector3 = _player.get_floor_normal()
	print("%3d  %-5s  %d    %7.3f  %7.3f  %8.3f  %+7.4f   %5.3f  duck=%.3f dv=%+.3f slides=%d air=%.3f crouch=%s"
			% [_frames - SETTLE, str(_player.is_on_floor()), _player.state,
			   _player.velocity.x, _player.velocity.y, p.y, p.y - gy, n.y,
			   _player.duck_amount, _player.duck_vel, _player.get_slide_collision_count(),
			   _player.air_time, str(not _player.collision_crouching.disabled)])