Does this code correctly gives an impact force? I’m new to programming so let me know nay monstrosities you see in my code.
extends CharacterBody2D
var gravity = 980
var weight = 0
var mass = 0.10
#Force on impact
var last_velocity = Vector2.ZERO
var force = 0
var seconds = 0
func _physics_process(delta: float) → void:
if not is_on_floor():
velocity.y += gravity * delta
#This is the falling time, Maybe not real seconds but workds as a timer.
seconds += 1 * delta
#This gets the last velocity when it colides with the floor
last_velocity = get_real_velocity()
else:
#Impact force… I guess
force = (mass * last_velocity) / seconds
print(force.y)
velocity.y = 0
seconds = 0
move_and_slide()