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

Author Topic: Moving in radial lines.  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

JasonMcG

  • Newbie
  • *
  • Posts: 10
    • View Profile
Moving in radial lines.
« on: September 17, 2017, 09:43:19 pm »
Hi,

I have a player that is confined to move around along a circle of set radius.
I want an object that should appear from the center of this circle to fly out at the player in a straight line and continue pass him. How do I go about doing this?

I can understand to get the players position and take the difference and use vector maths, but that would mean the object would stop flying once it reaches the players position at that time. How do I make it continue flying, until it goes off screen?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Moving in radial lines.
« Reply #1 on: September 17, 2017, 10:02:25 pm »
If the object never changes the direction then just store the initial move and keep applying it until it's offscreen.
If that's not it then maybe an image or code example would help.
Back to C++ gamedev with SFML in May 2023

JasonMcG

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Moving in radial lines.
« Reply #2 on: September 17, 2017, 10:13:17 pm »
Code: [Select]
void Player::move(){
    angle = 0.5;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
        transform.rotate(angle, {600, 350});
    }

I have defined the center as (600, 350).
An object will appear at the center and should fly radially outwards in a straight line to the players position.
I'm thinking,
Code: [Select]
player->getPosition() ? and take the difference between the player and object.
But then how to make the object fly past the player?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Moving in radial lines.
« Reply #3 on: September 17, 2017, 10:51:59 pm »
Store difference between player and center and then keep adding that to object position (with right length to get right speed).
Back to C++ gamedev with SFML in May 2023