Topic was automatically imported from the old Question2Answer platform.
Asked By
pafos_kota
in short: “the less health, the slower you move”
the player’s code is written like in a typical top-down shooter
I just want to make a horror game where the player’s speed will play an important role.
here’s some code:
const ACCELERATION = 700
const FRICTION = 1000
const MAX_SPEED = 95
var velocity = Vector2.ZERO
-----------------------------
export (int) var start_hp : int = 3;
onready var hp := start_hp;
var can_take_damage = true;
func take_damage():
if (can_take_damage):
can_take_damage = false;
hp -= 1;
animationFrisk.play("Hit");
else:
return;
where:
state_in = the current hitpoints
from_in = the lowest hitpoints (ths hp where the character is the slowest)
to_in = the highest hitpoints (the hp where the player is at full speed)
from_out = the lowest acceleration
to_out = the highest acceleration
returns the current acceleration
this will blend/return the acceleration in relation to the hitpoints
GDScript already has a range_lerp function that does just this