Hello, i wanted to make a character move around a planet but i had a few problems in the way. I made so my character moves on a specific path around a planet based on it’s center. I wanted to have gravity in the game so everything is gonna fall on the planet i have with a specific angle on every side of the planet normaly and not just float and move in a path like the character. I puted gravity but should i keep the player’s movement the same? I am breaking my head and i would like to have an opinion which way is better. Should i put em together or is there a better way?
Circle movement
What exactly is your problem? Are you just looking to orbit an object around your planet? If so, that’s quite simple:
FP.anchorTo(satellite, planet, orbitDistance);
FP.rotateAround(satellite, planet, orbitSpeed);
I feel a total idiot here… LOT OF THANKS FROM MY OWN PLANET HERE! I bypass a lot of commands… but you learn as you live. Thats what i need, but should i put these lines on the satellite itself or in the gameworld?
No need to feel dumb! It’s all a learning experience.
You can put these in either place, but if you put it in your satellite class you should obviously pass this instead of satellite.
Another obstacle in the way showed up. Everytime i put these 2 lines of code, my player just disappears. I didnt wanted to bother you again with something so simple, but i just have no idea how to fix it.
Here you go!
{
public var PLI:Image = new Image($PLI);
public function Player()
{
PLI.centerOrigin();
setHitbox(32, 32, 16, 16);
type = "player";
graphic = PLI;
layer = 2;
x = FP.halfWidth;
y = FP.halfHeight - 100;
}
override public function update():void
{
FP.anchorTo(this, Planet, 100);
FP.rotateAround(this, Planet, 10);
super.update();
}
}
Is Planet a class or a variable? The anchor object must be a variable and have an x and y property.
This one is the player (it should be moving around the planet). The planet’s code is same but it’s x and y are at the center of the screen. Both entites are extended in different packages.
Yeah, I understand that. What I’m asking is if “Planet” is the name of a class or the name of a variable. I don’t see a place where you initialize a variable called Planet.
If that’s the problem, you can get around it by setting Planet’s type to “planet”, and changing your rotation code to this:
var planet:Planet = world.getInstance("planet");
FP.anchorTo(this, planet, 100);
FP.rotateAround(this, planet, 10);
Sorry for taking so long to reply. I finally got it. Thanks again for your great help. Last question, is it hard to make the player rotate based on the side of the planet? Kinda like he is walking on it.
Do you mean change the angle of his graphic so his feet point “down”? That’s easy too!
image.angle = FP.angle(x, y, planet.x, planet.y);