1
I'm a beginner so i can't specifically say what the issue is but something to keep in mind. Type-casting from a float to an int loses precision. That could be causing a rounding error.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Why do you haveCode: [Select]this->Dest.x = (MousePos.x - this->GetSprite().GetPosition().x);
?
this->Dest.y = (MousePos.y - this->GetSprite().GetPosition().y);
It looks like you're creating a distance vector relative to the position of the sprite, but in your move function you're treating it like it was relative to the origin.
void DynamicEntity::MoveEvent(sf::RenderWindow &Window, sf::View View)
{
if(sf::Mouse::IsButtonPressed(sf::Mouse::Right))
{
sf::Vector2f MousePos(Window.ConvertCoords(sf::Mouse::GetPosition(Window).x, sf::Mouse::GetPosition(Window).y, View));
this->Dest.x = (MousePos.x - this->GetSprite().GetPosition().x);
this->Dest.y = (MousePos.y - this->GetSprite().GetPosition().y);
this->NewLoc = normalize(Dest);
this->SetIsMoving(true);
}
}
void DynamicEntity::Move()
{
if(this->GetIsMoving() == true)
{
if(this->GetSprite().GetPosition().x <= (Dest.x - 5.f) || this->GetSprite().GetPosition().x >= (Dest.x + 5.f))
{
this->MoveSprite(NewLoc.x * movSpeed, 0);
}
if(this->GetSprite().GetPosition().y <= (Dest.y - 5.f) || this->GetSprite().GetPosition().y >= (Dest.y + 5.f))
{
this->MoveSprite(0, NewLoc.y * movSpeed);
}
}
else
{
SetDest(this->GetSprite().GetPosition());
this->NewLoc = this->GetSprite().GetPosition();
this->SetIsMoving(false);
}
}