Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Jerry7 |
So I’m trying to do the following:
- Activate a CollisionShape2D
- If it collides with an object, move the player object up one unit at a time until there is no more collision
But even after I move the object for multiple loops, the collide()-function still detects a collision and it becomes an endless loop. Can anybody tell me what I’m doing wrong? Is there a better way of moving an object upwards on collision?
func _on_FloorDetect_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
if body is TileMap:
var tilemap = body as TileMap
var coordinate: Vector2 = Physics2DServer.body_get_shape_metadata(body_rid, body_shape_index)
var tileid = tilemap.get_cellv(coordinate)
var shape = shapes[0]["shape"]
var otherTrans = shapes[0]["shape_transform"]
if IdleCollision.disabled:
IdleCollision.disabled = false
var colliding = false
while true:
var trans = IdleCollision.transform
colliding = IdleCollision.get_shape().collide(IdleCollision.transform, shape, otherTrans)
if colliding:
global_position.y-=1
else:
break
Your indentation doesn’t look right.
Normally you move RigidBody’s with move_and_slide().
SteveSmith | 2023-01-22 12:13