0 votes

Hello!

im making a top down game.

the player is a kinematic body 2d that auto moves continually forward, you just rotate the direction. this works perfect, but i want that the player bounces forward (as in the image attached) when it collides with the tilemap world

enter image description here

this is the player movement code:

extends KinematicBody2D

var rotation_speed = 3
var rotation_dir = 0
var direction = 1
var speed = 50
var velocity = Vector2()

func _physics_process(delta):

    rotation += rotation_dir * rotation_speed * delta
    velocity = Vector2(speed, 0).rotated(rotation) * direction
    velocity = move_and_slide(velocity)

i've tried changing the last line with moveandcollide (times delta) but it doestn work. on a collision with the world, the player just gets stuck.

thank you very much!

in Engine by (71 points)

1 Answer

0 votes
by (830 points)
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.