• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
adamdaly

(another) planetary gravity question

7 posts in this topic

Hi, i've looked through a few topics on this but i can't find an answer. I understand - tentatively - how orbital gravity works, i've read and mostly understood the code examples given before. But what i don't understand is how an object such as a satelite when in orbit always retains its orientation relative to the object it is orbiting. Is this artificial or does it happen naturally? And if its natural how would this be incorporated in a script. I realise that i could reorientate based on previous position but if there is a physics explanation then i'd like to incorporate it.

adam
0

Share this post


Link to post
Share on other sites
If you are talking about artificial satellites always facing Earth, that is because they had a little bit of rotation put in by maneuvering thrusters to do so. If you are talking about Earth's moon, then the reason for it always having the same side face Earth is because of tidal effects.
0

Share this post


Link to post
Share on other sites
In general the orbit and the rotation of objects is independent of each other. The planets also rotate in their orbit around the sun... In case of satellites their orientation towards earth is intentional. Large enough bodies like the moon that are in relatively close orbit are a somewhat special case since tidal forces cause an energy transfer between rotation and orbital velocity. In the case of the Moon that lead to the moons rotation being coupled with it's orbit...
0

Share this post


Link to post
Share on other sites
Ah ok, thanks. It was really wrecking my head trying to figure out where that rotation could come from.

adam
0

Share this post


Link to post
Share on other sites
Right i've created a bit of code to create an orbiting planet. The values are just guess' at the minute, i'm not looking for accuracy yet.

[CODE]
import bpy
import mathutils
import math
for i in bpy.app.handlers.frame_change_pre:
bpy.app.handlers.frame_change_pre.remove(i)
star = bpy.data.objects['star']
planet = bpy.data.objects['planet']
planet.location = mathutils.Vector((0, 8, 0))
starMass = 40.0
planetMass = 1.0
G = math.pow(6.67300, 11)
def iterator(self):

r = (planet.location - star.location) * 100000

f = ((-G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2) * r.copy().normalized())

tangental_force = r.copy().normalized().cross(mathutils.Vector((0, 0, 1)))
print(tangental_force / 1000000)

planet.location += f
planet.location += tangental_force
#planet.location += r_cross

bpy.app.handlers.frame_change_pre.append(iterator)
[/CODE]

I've given the object a force that is constantly tangential to the force of gravity but i don't think that's the correct way to do this. If an asteroid was moving through space it wouldn't be able to apply a force tangential to gravity because it would have nowhere to get this force. Am i right?

adam
0

Share this post


Link to post
Share on other sites
You don't have to apply any force other than gravity. you just give the object an initial velocity and then energy conservation keeps it going (there is no atmosphere or friction to dissipate energy) and the gravitational force keeps it on its orbit.

But you need a correct integration scheme. location + force doesn't even make sense physically speaking.
The simplest way to do this is [url="http://en.wikipedia.org/wiki/Euler_method"]Euler integration[/url]:
[code]
v += dt*F/m
x += dt*v
[/code]
0

Share this post


Link to post
Share on other sites
Japro thanks for the help. I've implemented an integration method and it seems to be working well. I also wanted the objects to effect each other so i've added the equation f=ma.

[CODE]
import bpy
import mathutils
import math
import decimal
for i in bpy.app.handlers.frame_change_pre:
bpy.app.handlers.frame_change_pre.remove(i)
star = bpy.data.objects['star']
planet = bpy.data.objects['planet']
planet.location = mathutils.Vector((-8, 12, 0))
star.location = mathutils.Vector((0, 0, 0))
starMass = 600#3.42 * math.pow(10, 23)
planetMass = 1#2.03 * math.pow(10, 30)
dT = 1 / 24
G = -0.01#6.67300 * math.pow(10, -11)
planet_v = mathutils.Vector((0.8, -0.2, 0))
star_v = mathutils.Vector((0, 0 ,0))
def iterator(self):
frame = str(bpy.data.scenes['Scene'].frame_current) + ' '
global planet_v
global star_v

r = (planet.location - star.location)
planet_f = starMass * ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())
star_f = planetMass * ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())

planet_v += planet_f * math.pow(dT, 2)
star_v += star_f * math.pow(dT, 2)

planet.location += planet_v
star.location += star_v
bpy.app.handlers.frame_change_pre.append(iterator)
[/CODE]

To get the f=ma equation to work i've had to use the mass of the other object. It looks right once i run the simulation but is it correct.

adam
0

Share this post


Link to post
Share on other sites
[CODE]
gravity_force = ((G * (starMass * planetMass)) / math.pow(r.copy().magnitude, 2)* r.copy().normalized())
planet_v += ( gravity_force / planetMass) * dT
star_v += (-gravity_force / starMass ) * dT
[/CODE]

this should work. If the planets repel each other, swap the minus sign.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0