SFML: Monster following player on a straight line
Posted
by
user3504658
on Game Development
See other posts from Game Development
or by user3504658
Published on 2014-08-13T12:15:38Z
Indexed on
2014/08/19
16:31 UTC
Read the original article
Hit count: 279
sfml
I've searched for this and found a few topics , usually they used a function normalize and using simple vector subtracting which is ok , but how should I do it in sfml ? Instead of using:
Movement = p.position() - m.position();
p is the player and m is the monster
I used something like this to move on a straight line:
sf::Vector2f Tail(0,0);
if((mPlayer.getPosition().y - mMonster.GetInstance().getPosition().y) >= (mPlayer.getPosition().x - mMonster.GetInstance().getPosition().x)){
//sf::Vector2f Tail(0,0);
Tail.x = mPlayer.getPosition().x - mMonster.GetInstance().getPosition().x;
}
else if((mPlayer.getPosition().y - mMonster.GetInstance().getPosition().y) <= (mPlayer.getPosition().x - mMonster.GetInstance().getPosition().x)){
//sf::Vector2f Tail(0,0);
Tail.y = mPlayer.getPosition().y - mMonster.GetInstance().getPosition().y;
}
if(!MonsterCollosion())
mMonster.Move(Tail * (TimePerFrame.asSeconds() * 1/2 ) );
It works ok if the the height = the width for the game window, although I think it's not the best looking game when it comes to a moving monster, since it starts fast and then it gets slower
so what do you guys advise me to do ?
© Game Development or respective owner