0 votes

I am trying to create a small platform which left and right.I have an Area2D which detects at both ends of the platform's range.The platform doesn't reverse direction after the 5th collisionTwo Raycast2D'sare provided facing x and -x direction.I tried to solve this bug but i couldn't.I don't have much experience with Godot.Someone please help.

extends KinematicBody2D

var distance = 0
var velocity = Vector2(10,0)
onready var ray = get_node("RayCast2D")
onready var ray_2 = get_node("RayCast2D2") 

func _ready():

func _process(delta):
   while true:
      distance = distance + self.transform.x.x
       if ray.is_colliding() || ray_2.is_colliding():
           velocity.x = -velocity.x
      move_and_collide(-velocity * delta)
in Engine by (15 points)
edited by

Could You list the nodes you are using for me.
I don't understand this statement "I am trying to create a small platform which left and right"

Are you trying to shift the platform right and left? or
Are you trying to get an object to move left and right on the platform?
Is the platform supposed to rotate around center point?

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 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.