Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Question about orbiting planets

Author
Message
haliop_New
User Banned
Posted: 31st Dec 2016 13:29 Edited at: 31st Dec 2016 13:35
so i have an Earth planet and the Moon planet in my game
i can orbit them using Sin and Cos
but one thing is unclear to me
how can i add the x y z positions of the planet Earth if its not on 0,0
cause i play with it a bit

how can i use Sin and Cos in a way that it will orbit at a new given location rather then just 0,0,0
please help

pseudo code will be very helpful
thank you for your time.
haliop.

edit:
for the example
lets say
planet earth is at 150000000,0,150000000
and the moon is at 150000000-346000,0,150000000

how do i add the current x and current z to the sin/cos algo ?
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 31st Dec 2016 14:11
I did a sort of similar thing in my game, as everything rotates around a 3D tower. What I did, between syncs, was to position everything at the center of its "orbit", rotate it accordingly to it's rotation around the tower, then did a local translation so that the object moved out from the central pivot of its orbit and ended up in the correct position before the next sync.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 31st Dec 2016 17:17 Edited at: 31st Dec 2016 17:35
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
haliop_New
User Banned
Posted: 1st Jan 2017 08:37
Ortu you are the best !
i thought it would look something similar
now im wondering if i should stop assuming i know stuff just do them see what happens

this is awesome thank you man. really appreciate it.

CumQuat i didnt really understand what your'e saying
CumQuaT
AGK Master
13
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 1st Jan 2017 13:33
I must have misunderstood the question :\
Ched80
13
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 1st Jan 2017 14:27
Be careful with the values you are using, AppGameKit tier 1 only holds 7dp. This can affect how smooth your orbits are in game.
haliop_New
User Banned
Posted: 1st Jan 2017 16:41
Ched its just for scenery
but can you explain a bit more ?
what should i look at ? or be warned about ?
a bit of explanation will be awesome.
thank you.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 1st Jan 2017 16:53
Using numbers larger than 7 digits (I think are truncated) values may not behave as you expect
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
haliop_New
User Banned
Posted: 17th Jan 2017 11:13
Ortu , This dosent work well
the moon collides with Earth...

can someone help ?
I don't know how to get SIn and Cos to work from a starting location which is far from the object its orbating and keeping the same distance

what Ortu suggests just puts the moon at a location which is yes far enough from earth using the distance I entered but it dosent orbit earth very well...
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Jan 2017 12:07
sin / cos give you a value between -1 and 1 , so its left/right up/down if you useing it for x and y axis, the angle parameter from 0-360° (in circle) just belongs the output from -1 to 1
it is not necessary to use sinus and cosinus but it is still frequently used.
if you multiply a length with this -1 until 1 for one axis it is more left or right but if you multiply for x and y axis you go along this direction, so this result describes a position at x,y axis.
this sin/cos thing always rotate around x=0,y=0
if you will rotate the moon around the earth but earth have a position 20,10 you must subtract is first, get new values from sin * distance & cos * distance and add this 20,10 again.

AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
haliop_New
User Banned
Posted: 17th Jan 2017 12:15
this is what I currently use but its not good



you said you need to add the values of earth positions but that's not good....
how would you fixed it ?
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 17th Jan 2017 15:07 Edited at: 17th Jan 2017 16:36
Could be a rounding error caused by a wrong variable type, or incorrect angle calculation.

I set up a demo code which orbits earth around the sun and the moon around earth, using simple sin/cos calculations. Maybe you can locate your bug by having a look at it




Cheers,
PSY
PSY LABS Games
Coders don't die, they just gosub without return
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Jan 2017 15:30
Quote: " but its not good "

the values you will see if you set a break point and start in debugmode and add this variables in the watch list.
AGK (Steam) V2017.01.09 : Windows 10 Pro 64 Bit : AMD (16.12.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Jan 2017 12:37
Browse through the AppGameKit Challenge thread, not long ago we made solar system simulations. If you want accurate planet orbits the data is all there.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
haliop_New
User Banned
Posted: 19th Jan 2017 13:30
still not working well...
I think its because I use the 3d world in millions of units maybe AppGameKit cant handle 10000000 and such numbers...
i'll try to create a simple app to check it but currently its not working the moon and earth still collides....
haliop_New
User Banned
Posted: 19th Jan 2017 13:31
OOPS MY BAD

it does work I used GetObjectY for the Z value that is why they collided.

thanks everyone for the help , really appreciate it .

haliop.

Login to post a reply

Server time is: 2024-04-26 07:11:41
Your offset time is: 2024-04-26 07:11:41