im trying to calculate player damage. the damage won’t be linear as I’m trying to make an undertale-inspired combat system, where you have to interact with a key and hit the right spot to make the most damage, so i am using a curve.
When I tested it out, however, no matter where I hit in the damage circle, i always get zero! i don’t know how to fix that. How do i fix this? Here is the code for reference:
const PLAYER_DAMAGE: Curve = preload(“uid://svpkelbrid1a”)
var distance_from_centre: int = roundi(abs(targetbar.global_position.x - skillcheck_center.global_position.x))
var damage: int = player_strength * PLAYER_DAMAGE.sample(distance_from_centre)
I made a variable relative to the targetbar’s position from the center, that is a node I put at the center of the damage circle.
here is also the curve for reference. It is just a normal curve, it is not a Curve2D or 3D.
It’s because you are using distance_from_centre as the input for sample of curve.
Curve takes a normalized input, which means a float between 0 and 1.
And it’s very likely that your distance_from_centre is more than 1. So curve sample always returns the value of input 1 (which is the maximum input you can have). And that value is set as 0 by you.
You should normalize your distance_from_centre.
const PLAYER_DAMAGE: Curve = preload(“uid://svpkelbrid1a”)
var max_distance :float = damage_circle_width / 2.0
var distance :float = abs(targetbar.global_position.x - skillcheck_center.global_position.x)
var normalized_distance :float = distance / max_distance
normalized_distance = clamp(normalized_distance, 0.0, 1.0)
var damage: int = player_strength * PLAYER_DAMAGE.sample(normalized_distance)
you’re using ints, ints can’t be used to do percentage values as they are numbers like 0,1,2,3,4,5 ect. not 0.1, 0.2
also your distance isn’t even percentage, it’s just number, how would you reference value from 0-1 if you have 20 as your distance?
const CURVE: Curve = preload("...")
var radius: float = 5 ## it's the maximum size of your circle, everything greater is infinity / the same
var distance: float = abs(targetbar.position.x - skill.position.x) ## e.g let's say it'll give us 3.4
var percentage: float = distance / radius ## 3.4 / 5 = 17/25 ~ 0.68
var damage: float = CURVE.sample(percentage) ## it gives 0.7, i've set the curve as yours in my godot
hope this helped a little