Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RockZombie4 |
Recently, I have made a player in Godot which can move forward, backward, gets rotated with the mouse, and can dash. I have also added a collision box to it so it will (hopefully) be able to detect when it has collided with a moving obstacle. The problem is: I don’t know how to make a moving obstacle with a collision box. Here is the code for the player(sorry, I don’t have a link for the images):
extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2(250,250)
func get_input():
look_at(get_global_mouse_position())
velocity = Vector2()
if Input.is_action_pressed("down"):
velocity = Vector2(-speed, 0).rotated(rotation)
if Input.is_action_pressed("up"):
velocity = Vector2(speed, 0).rotated(rotation)
if Input.is_action_pressed("dash"):
velocity = Vector2(700, 0).rotated(rotation)
if Input.is_action_pressed("dash2"):
velocity = Vector2(-700, 0).rotated(rotation)
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)
Can someone help me?