Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Yamz |
I have an enemy that moves and detects the ground and you look like them, it has two lines that detect if an enemy is approaching, everything works fine until the enemy collides with a tilemap block and then I get this error.
Trying to assign a value of type ‘TileMap’ to a variable of type ‘KinematicBody2D’.
var player: KinematicBody2D = null
var velocity = Vector2 ()
var distance = Vector2 ()
var speed = 120
var direction = Vector2 (-1.0)
func _physics_process (delta):
.apply_gravity (true, delta)
var t = self.transform
t [2] .x + = 5 if address.x == 1 else -5
if! test_move (t, Vector2 (5.2)):
address.x = -1
$ Spr.flip_h = false
elif! test_move (t, Vector2 (-5,2)):
address.x = 1
$ Spr.flip_h = true
if is_on_wall ():
address.x = 1 if address.x == -1 else -1
$ Spr.flip_h = false if $ Spr.flip_h == true else true
if $ Left.is_colliding () and! player:
player = $ Left.get_collider ()
direction.x = -1
$ Spr.scale = Vector2 (-direction.x, 1)
emit_signal ("attack", "Attacking")
elif $ Right.is_colliding () and! player:
player = $ Right.get_collider ()
direction.x = 1
$ Spr.scale = Vector2 (-direction.x, 1)
emit_signal ("attack", "Attacking")
if! $ Left.is_colliding () &&! $ Right.is_colliding ():
player = null
I BELIEVE THAT THE ERRO IS GIVEN BY THE RAYCAST COLICIONA WITH THE TILEMAP AND THIS IS ASSIGNED TO THE VARIABLE PLAYER BUT THIS ONLY ALLOWS KINEMATICBODY2D, HOW IT COULD BE SOLUSED!