hey, i tried to go to sonic physics guide from sonic retro, but i failed and i couldn't be able to implement it and i got stuck, so can you guys modify my code and make it do the sonic physics so i can copy and paste it to my player script.
here is my script for all of you to modify and make it do the sonic-like 360 degree slope movement, my player has no timers and no raycasts yet, or atleast help me how to do it in my code easily.
`extends CharacterBody2D
class_name Player
var maxSpd = 900
var jumpSpd = 320
var acc = 200
var dec = 700
var angle = 0
var fric = 200
var grav = 518.75
var decelerateOnJumpRelease = 0.5
enum states {Free}
var currentState = states.Free
Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if is_on_floor():
var floor_normal = get_floor_normal()
angle = floor_normal.angle() + deg_to_rad(90) # angle relative to horizontal
else:
angle = 0 # reset when in air
$Sydilix_Sprite.rotation = lerpf($Sydilix_Sprite.rotation, angle, 0.25)
$Sydilix_Sprite.scale.x = lerpf($Sydilix_Sprite.scale.x, 1, 0.1)
$Sydilix_Sprite.scale.y = lerpf($Sydilix_Sprite.scale.y, 1, 0.1)
$CollisionMask.rotation = angle
match currentState:
states.Free:
stateFree(delta)
move_and_slide()
func stateFree(delta:float):
var inputDir = Input.get_axis("left", "right")
if is_on_wall():
velocity.x = 0
if not is_on_floor():
velocity.y += grav * delta
$Control/RichTextLabel.text = str(velocity.x)
if inputDir:
if inputDir * velocity.x < 0:
velocity.x = move_toward(velocity.x, inputDir * maxSpd, dec * delta)
else:
velocity.x = move_toward(velocity.x, inputDir * maxSpd, acc * delta)
else :
velocity.x = move_toward(velocity.x, 0, fric * delta)
if is_on_floor() and Input.is_action_just_pressed("jump"):
if Input.is_action_pressed("down"):
position.y += 1
else:
velocity.y = -jumpSpd
$Sydilix_Sprite.scale = Vector2(0.75, 1.25)
if Input.is_action_just_released("jump") and velocity.y < 0:
velocity.y *= 0.5
if velocity.x > 700 or velocity.x < -700:
acc = 5
else:
acc = 200
# animations
if velocity.x < 0:
$Sydilix_Sprite.flip_h = true
elif velocity.x > 0:
$Sydilix_Sprite.flip_h = false
if is_on_floor() and velocity.x != 0:
if velocity.x > 880 or velocity.x < -880:
$animation.play("Peel Out")
$animation.speed_scale = velocity.x / 200
elif velocity.x > 700 or velocity.x < -700:
$animation.play("Run")
$animation.speed_scale = velocity.x / 200
else:
$animation.play("Walk")
$animation.speed_scale = velocity.x / 200
elif not is_on_floor() and velocity.y != 0:
if velocity.y < 0:
$animation.play("Jump")
$animation.speed_scale = 1
elif velocity.y > 0:
if $animation.current_animation != "FallLoop":
$animation.play("Fall")
$animation.speed_scale = 1
else:
$animation.play("Idle")
$animation.speed_scale = 1
func transition_to_fall_loop():
$animation.play("FallLoop")