I have an arrow entity I made that I would like to stick to a movable block entity when they collide. How can I accomplish this?
My attempt half works. The arrow will stick to the object but won’t budge when the other entity is moved until it is about to stop colliding.
Here is a sample of what I came up with. This is the update function in my Arrow class.
override public function update():void
{
checkCollision();
if (collided == false)
{
if (facing == "down")
moveBy(0, speed);
if (facing == "up")
moveBy(0, -speed);
if (facing == "right")
moveBy(speed, 0);
if (facing == "left")
moveBy( -speed, 0);
}
else
{
x = collidedObj.x - distanceX;
y = collidedObj.y - distanceY;
}
if (timer >= 500)
world.remove(this);
else
timer++;
}
and this
private function checkCollision():void
{
if (collide("solid", x , y))
{
collidedObj = collide("solid", x, y);
collided = true;
distanceX = collidedObj.x - x;
distanceY = collidedObj.y - y;
}
}