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

Author Topic: SFML cicrle movement  (Read 2285 times)

0 Members and 1 Guest are viewing this topic.

mitop

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
SFML cicrle movement
« on: December 21, 2018, 03:50:23 pm »
Does anybody know how to make something like circle movement in SFML? I would like to make some game with tank as main character. Its moveing only forward or backward and rotate. So how can i apply movement to degree? Sorry for my languga mistakes and tell me if i wrote something incorrectly! Thanks for any respond.

Okay i know for everybody that wants to know:
body.move( -sin(body.getRotation()*3.14159265 / 180)*-3, -cos(body.getRotation()*3.14159265 / 180) * 3);
« Last Edit: December 21, 2018, 04:24:58 pm by mitop »

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: SFML cicrle movement
« Reply #1 on: December 22, 2018, 06:27:07 pm »
body.move( -sin(body.getRotation()*3.14159265 / 180)*-3, -cos(body.getRotation()*3.14159265 / 180) * 3);

I don't know what that is but my advice is to read the official tutorials such as:

https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php

Kanoha

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: SFML cicrle movement
« Reply #2 on: December 23, 2018, 04:02:10 pm »
body.move( -sin(body.getRotation()*3.14159265 / 180)*-3, -cos(body.getRotation()*3.14159265 / 180) * 3);

I don't know what that is but my advice is to read the official tutorials such as:

https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php
Mitop's solution is perfect for the problem he wants to solve. The graphics tutorial page don't show how to do it, simply because the issue isn't related to SFML, but to general mathematics.
« Last Edit: December 23, 2018, 04:05:04 pm by Kanoha »

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: SFML cicrle movement
« Reply #3 on: December 24, 2018, 12:07:15 am »
Hi Guys

I have one doubt: shouldn't the rotation attribute be updated after that formula? Or it is automatically?


body.move( -sin(body.getRotation()*3.14159265 / 180)*-3, -cos(body.getRotation()*3.14159265 / 180) * 3);

If you don't do this

body.setRotation(body.getRotation() + rotation);

wouldn't it go like by a line (constant)?