0 votes

hi, i got this scene with 4 staticbodies and its respective collision shapes limiting top, down, left and right screen position, and a kinematicbody2d with its collision shape;

found this code twice in an old question here and in godot docs introduction to vectors, except by one line code its identical so more or less i grasp it.

kinematicbody2 constant bounces as expected and it keeps the force, so each bounce get same height.
if i drop kinematic body at posy 80 it bounce back at posy 80, if i drop it at 150 it bounces back at 150.

but what i want to achieve is that it bounce back at a desired height indepently where it was dropped, so if i droped it at 150 i want it to bounce back at 80 and keep same height each time, what do i need?.

extends KinematicBody2D

var velocity = Vector2(60,0) #horizontal and vertical forces

func _ready():
pass

func physicsprocess(delta):
velocity.y += 500 * delta #vertical applied force
var collision = moveandcollide(velocity * delta)
if collision:
var motion = collision.remainder.bounce(collision.normal)
velocity = velocity.bounce(collision.normal)
#velocity.y = -400 #cheating here without success
moveandcollide(motion)
pass

in Engine by (106 points)

Please log in or register to answer this question.

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 webmaster@godotengine.org with your username.