I am trying to implement Impact force and I need the last velocity when the object/player collides with the floor in a free fall.
extends CharacterBody2D
#Body parameters/ Body information
var gravity = 980
var weight = 0
var mass_1 = 0.10
#Just trying to get the last velocity
var last_velocity = Vector2.ZERO
#Some protptype seconds
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
last_velocity.y = velocity.y
else:
velocity.y = 0
seconds = 0
move_and_slide()
if last_velocity.y > velocity.y:
print(last_velocity)
Got this bad boy. lets test
I think this bad boy does the trick.
extends CharacterBody2D
#World gravity
var gravity = 980
#Body parameters/ Body information
var weight = 0
var mass = 0.10
#Just trying to get the last velocity
var last_velocity = Vector2.ZERO
#Some protptype seconds dont mind this yet, but it kinda works
var seconds = 0
func _physics_process(delta: float) → void:
if not is_on_floor():
#This adds value to the velocity
velocity.y += gravity * delta
#This stores the velocity in another variable
last_velocity.y = velocity.y
print("Last velocity: ", last_velocity)
else:
velocity.y = 0
seconds = 0
move_and_slide()
#This should get the impact when the object hits the ground! And use the lastvelocity as the "last velocity"
if last_velocity.y > velocity.y:
var impact_force = 0
impact_force = mass * last_velocity.y / delta
print("last Force", impact_force)
And there is no such a func called get_last_slide_velocity()