This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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;"Hit");
Godot version 3.3.2
in Engine by (32 points)

1 Answer

+1 vote

you can write a simple function to calculate this:

func linear_blend( state_in:float, from_in:float, to_in:float, from_out:float, to_out:float ):
return from_out + (to_out - from_out) * ((state_in - from_in) / (to_in - from_in))

statein = the current hitpoints
in = the lowest hitpoints (ths hp where the character is the slowest)
toin = the highest hitpoints (the hp where the player is at full speed)
out = the lowest acceleration
to_out = the highest acceleration
returns the current acceleration

this will blend/return the acceleration in relation to the hitpoints

by (4,088 points)

GDScript already has a range_lerp function that does just this :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.