Hello:
I believe the formula you are looking for goes something like this:
satellite.x = body.x + (body.width/2) + Math.cos(angleofBodyInDegrees) * DistanceFromBodyCenter;
satellite.y = body.y + (body.height/2) + Math.sin(angleofBodyInDegrees) * DistanceFromBodyCenter;
It's from an old formula I was using in Flixel, I hope it's still relevant. I believe what I was trying to do with the body.x + (body.width/2), body.y + (body.height/2) parts of the code was get the center of the body? I forget. I hope this helps!
Edit: Whoops, I think the angle of the body ought to be in radians, not degrees.
Edit 2: Okay, it's sloppy, but here's a simple program that should demonstrate everything:
#include <SFML/Graphics.hpp>
#include <cmath>
const double PI = 3.14159265;
int main()
{
// Create the main window
sf::RenderWindow App(sf::VideoMode(400, 300, 32), "SFML Events");
sf::Shape Rect = sf::Shape::Rectangle(0, 0, 50, 50, sf::Color::Green);
Rect.SetCenter(25, 25);
Rect.SetX(200);
Rect.SetY(150);
sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 24, 24, sf::Color::Blue);
Rect2.SetCenter(12, 12);
// Start main loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
if (App.GetInput().IsKeyDown(sf::Key::Up)) Rect.Move(0, -80 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) Rect.Move(0, 80 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Left))
{
Rect.SetRotation(Rect.GetRotation() - 1 * ElapsedTime * 100);
}
if (App.GetInput().IsKeyDown(sf::Key::Right))
{
Rect.SetRotation(Rect.GetRotation() + 1 * ElapsedTime * 100);
}
float BodyAngle = Rect.GetRotation() * PI / 180;
Rect2.SetX(Rect.TransformToGlobal(Rect.GetCenter()).x + (sin(BodyAngle) * 80));
Rect2.SetY(Rect.TransformToGlobal(Rect.GetCenter()).y + (cos(BodyAngle) * 80));
// Clear the screen (fill it with white color)
App.Clear(sf::Color(255, 255, 255));
// Draw player
App.Draw(Rect);
App.Draw(Rect2);
// Display window on screen
App.Display();
}
return EXIT_SUCCESS;
}