PDA

View Full Version : Problem with QGraphicsItem change rotation to point towards another item.



jbeougher
28th December 2013, 04:39
I am attempting to have an item point towards another item using QLineF. This should update during the advance function of the program.


void ship::advance(int step)
{
if (!step)
{
return;
}

QLineF lineToTarget(mapToScene(pos()),mapToScene(target->pos()));

setRotation(lineToTarget.angle());

setPos(x() + speed, y());

qDebug() << target->x() << x() << lineToTarget.angle();

}

The problem I'm having is sometime the angle is correct and other time if the position change the item is not pointing the correct direction towards the target. I am trying to understand how I can make this work. mapToScene and mapFrom Scene still confuse me on how they should work. My final goal is to have an item be able to chase another item that both are moving.