![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | alink |
hey every one, I need help for this script it shows no error on compiler but when I run the game there is a error : Invalid operands’Vector2’ and ‘int’ in operator’>='.
here is the script , error line 23:
extends KinematicBody2D
export(float) var move_speed = 100
export(float) var run_speed = 200
export(float) var waypoint_arrived_distance = 10
export(bool) var faces_right = true
export(Array, NodePath) var waypoints
export(int) var starting_waypoint = 0
var waypoint_position
var waypoint_index setget set_waypoint_index
var velocity = Vector2.ZERO
onready var animated_sprite = $AnimatedSprite
func _ready():
self.waypoint_index = starting_waypoint
func _physics_process(delta):
var direction = self.position.direction_to(waypoint_position)
var distance_x = Vector2(self.position.x, 0).direction_to(Vector2(waypoint_position.x, 0))
if(distance_x >= waypoint_arrived_distance):
var direction_x_sign = sign(direction.x)
velocity = Vector2(
move_speed * direction_x_sign,
min(velocity.y + GameSetting.gravity, GameSetting.terminal_velocity)
)
if(direction_x_sign == -1):
animated_sprite.flip_h = faces_right
elif(direction_x_sign == 1):
animated_sprite.flip_h = faces_right
move_and_slide(velocity, Vector2.UP)
else:
var num_waypoints = waypoints.size()
#loop through waypoints
if(waypoint_index < num_waypoints - 1):
self.waypoint_index += 1
else:
waypoint_index = 0
func set_waypoint_index(value):
waypoint_index = value
waypoint_position = get_node(waypoints[value]).position