0 votes

I am working on a platformer, i'm currently trying to make a little blob guy follow you around, by ducking under platforms, and re apearing at your position, snapped to a tileset. However, if you land on the edge of a platform, his position gets rounded, and he apears off the edge. What I am trying to do is make it so he only pops up if he is colliding with the tileset. However, the body entered and exit signals only run once, and I can't get it to work. Any ideas? `var collide = false
var targetY = 0
var targetX = 0
var squat = false
signal squat_anim
onready var player = $"../KinematicBody2D"

func physicsprocess(delta):
if position.distanceto(player.position) > 300 and !squat:
emit
signal("squatanim")
if collide and !squat:
$Sprite.frame = move
toward($Sprite.frame, 0, 100 * delta)
else:
$Sprite.frame = move_toward($Sprite.frame, 8, 100 * delta)

func ondemonsquatanim():
squat = true
while $Sprite.frame != 8:
yield(gettree(), "idleframe")
yield(player, "isonfloor")
position = player.position.snapped(Vector2(64, 0))
squat = false

func ondemonbodyentered(body):
print("enter")
collide = true

func ondemonbodyexited(body):
print("exit")
collide = false`

Godot version 3.4 stable
in Engine by (40 points)

1 Answer

0 votes

I worked a lot with tilemaps and I would make a function to recognize if given global position is connected to certain tile of tileset, like a platform. If I understand your code correctly You could just apply this function around this line :

position = player.position.snapped(Vector2(64, 0))

To check if this snapped position translated with worldtomap() is in fact platform or above platform with get_cell(), before you teleport your blob.

by (5,252 points)
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.