Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shape following cursor at a certain speed  (Read 6489 times)

0 Members and 1 Guest are viewing this topic.

itsaincosh

  • Newbie
  • *
  • Posts: 1
    • View Profile
Shape following cursor at a certain speed
« on: October 08, 2021, 04:41:15 pm »
So, we're trying to make a CircleShape follow the mouse's position at a speed of 500 pixels per second. We're like super noobs to SFML (like just started learning last week after learning C++ the week before).

We know the code for the circle following the mouse is...

//while window is open blah blah we have other code here so we only posted the relevant code
sf::CircleShape cursor;
cursor.setRadius(10.0f);
cursor.setFillColor(sf::Color::Yellow);
cursor.setPosition(WINDOW_W, WINDOW_H);

while (window.pollEvent(event)) {
        sf::Vector2f mousePos = sf::Vector2f(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
        cursor.setPosition(mousePos);
}
 

But we don't know how to get the circle to follow the mouse slowly. We tried cursor.move and even did some trigo sh** but we don't understand it enough to make sense of it. If someone could help, that would be great!

codingHere

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Shape following cursor at a certain speed
« Reply #1 on: October 09, 2021, 03:39:02 am »
try making 2 variables of speed (about 450.0f) and mouse pos.(vector2f) then tell it to move towards that with the speed of the speed variable   :)

 

anything