• Create Account

### #ActualCarlows

Posted 30 June 2013 - 11:37 AM

I would just keep one vector for the speed, then add the normalized mouse direction vector to it:

Vector2f position;
Vector2f speed;

void Nave::update(sf::Time& delta, sf::Vector2f mousePOS)
{
float mouseMagnitude = sqrt(mousePOS.x * mousePOS.x + mousePOS.y * mousePOS.y)
mousePOS = mousePOS / mouseMagnitude;  // probably need to divide this by some constant, too.
speed += mousePOS;
position += speed; // * delta if this is not called at regular intervals
}


I think that doesn't change anything on the behavior...

I think it does: I am treating the speed as a vector, while your "acceleration" (actually speed, I think) is a scalar.

You were right, my fault. Thanks!

### #1Carlows

Posted 30 June 2013 - 11:37 AM

I would just keep one vector for the speed, then add the normalized mouse direction vector to it:

Vector2f position;
Vector2f speed;

void Nave::update(sf::Time& delta, sf::Vector2f mousePOS)
{
float mouseMagnitude = sqrt(mousePOS.x * mousePOS.x + mousePOS.y * mousePOS.y)
mousePOS = mousePOS / mouseMagnitude;  // probably need to divide this by some constant, too.
speed += mousePOS;
position += speed; // * delta if this is not called at regular intervals
}


I think that doesn't change anything on the behavior...

I think it does: I am treating the speed as a vector, while your "acceleration" (actually speed, I think) is a scalar.

You were right, my bad. Thanks!

PARTNERS