Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Godene |
I am doing a 2D tutorial involving a player, enemies, coins and tilemaps etc.
I am having a problem where an enemy seems to be having a problem with a tile. Error says Invalid call. Nonexistent function ‘ouch’ in base ‘TileMap’. I am not sure why this would occur. Everyone was getting ok until some change occurred.
I have had to replace one way tiles with solid tiles so that the enemy would go there now.
a ‘body’ Object ID 1356 is apparently a solid Tilemap according to the node path. The other, Object 1410, is an enemy. The error looks at line 47 at function: _on_sides_checker_body_entered. The enemy also has a floor and cliff checkers, which maybe where the problem arises? Here is the code in the enemy node…
extends KinematicBody2D
var speed = 50
var velocity = Vector2()
export var direction = -1
export var detect_cliffs = true
func _ready():
if direction == 1:
$AnimatedSprite.flip_h = true
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction
$floor_checker.enabled = detect_cliffs
if detect_cliffs:
set_modulate(Color(1.2,0.5,1))
func _physics_process(delta):
if is_on_wall() or not $floor_checker.is_colliding() and detect_cliffs and is_on_floor():
direction = direction * -1
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction
#helps raycast detect cliffs from side in direction going
velocity.y += 20
velocity.x = speed * direction
velocity = move_and_slide(velocity, Vector2.UP)
func _on_top_checker_body_entered(body):
$AnimatedSprite.play(“squashed”)
speed = 0
set_collision_layer_bit(4,false)
set_collision_mask_bit(0,false)
$top_checker.set_collision_layer_bit(4,false)
$top_checker.set_collision_mask_bit(0,false)
$sides_checker.set_collision_layer_bit(4,false)
$sides_checker.set_collision_mask_bit(0,false)
$Timer.start()
body.bounce()
$SoundSquash.play()
func _on_sides_checker_body_entered(body):
print(“ouch!”)
body.ouch(position.x) #tells steve.gd info for jumping
func _on_Timer_timeout():
queue_free()