Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | gcivico |
Hi.
I want to detect collision using move_and_slide
and get_slide_collision
. That is to get the normal and know when the tile is a slope. This is my code:
extends KinematicBody2D
const Gravity = Vector2(0,500)
const Speed = 500
var linearVelocity = Vector2()
func _physics_process(delta):
linearVelocity.y += Gravity.y * delta
var left = Input.is_action_pressed("ui_left")
var right = Input.is_action_pressed("ui_right")
var horizontalForce = true
if left:
linearVelocity.x = -Speed
horizontalForce = false
if right:
linearVelocity.x = Speed
horizontalForce = false
if horizontalForce:
linearVelocity.x = 0
var normal = Vector2(0,-1)
linearVelocity = move_and_slide(linearVelocity,normal)
var col = get_slide_collision(0)
All is fine but when I add the var col = get_slide_collision(0)
the game turn slow.
What is the correct way to do this?