0 votes

I'm fairly new to Godot and game development in general really. The last project I worked on was also my first and it was just a small python game made out of spaghetti code without an engine. So, needless to say, I have no idea what I'm doing. Currently I'm struggling with making my code detect and react to a collision between two objects. The player, a KineticBody2D, and spikes, a StaticBody 2D. I want to make it so the player is moved to an empty layer and falls through the map if they touch the spikes collider, then the scene is regenerated to act as a death mechanic.

Here is my current code for the player:

extends KinematicBody2D

const UP = Vector2(0, -1)
var speed = Vector2()
export(Vector2) var velocity:Vector2=Vector2(500,0)

func _physics_process(delta):
    speed.y += 9.8

var collision_info=move_and_collide(velocity*delta)
if collision_info:
    velocity=velocity.bounce(collision_info.normal)

if is_on_floor():
    speed.y = 9.8
    if Input.is_key_pressed(KEY_W):
        speed.y = -400

if Input.is_key_pressed(KEY_D):
    speed.x = 150
elif Input.is_key_pressed(KEY_A):
    speed.x = -150
else:
    speed.x = 0


move_and_slide(speed, UP)
in Engine by (14 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 [email protected]g with your username.