question about gravity in 3d

Blitz3D Forums/Blitz3D Beginners Area/question about gravity in 3d

Rubiks14(Posted 2005) [#1]
ok I'm wondering how you set a certain area as the point that pulls everything toward it, like if you have a sphere and you want the very center of it to pull everything to it so like if someone is walking on the sphere then if they move to the bottom of the sphere they will stay on it instead of falling off (like the earth).
or if you wanted to have a plane at the bottom of the level to be the point of gravity (so u would slip down steep hills)


jfk EO-11110(Posted 2005) [#2]
moving things twoards the center of a sphere if not as easy as simply move things down. Usually I only need to:
translateentity player,0,-.2,0

to move the character 0.2 units towards the ground.

If you would like to have a spherical gravity, you could create a pivot in the center of the planet, then do the following:

a_p#=entitypitch(player,1)
a_y#=entityyaw(player,1)
a_r#=entityroll(player,1)
pointentity player, center
moveentity player,0,0,0.2
rotateentity player a_p,a_y,a_r,1


Of course, whatever you do, you need to set up a proper collision handling unless you plan to sink into the ground.


Matty(Posted 2005) [#3]
Try this:


Graphics3D 800,600,32,2

camera=CreateCamera()


planet=CreateSphere()
thing=CreateCube()


EntityType planet,2
EntityType thing,1
Collisions 1,2,2,2
MoveEntity camera,0,0,-25


Const GravityStrength#=0.1


initialpositionx#=20.0 ;initial start position of your 'thing'
initialpositiony#=0.0
initialpositionz#=0.0


velocityx#=0.0 ;initial start velocity of your 'thing' try changing these
velocityy#=0.0
velocityz#=0.0

;example - thing orbiting a planet 
;
;velocityx#=0.0
;velocityy#=0.075
;velocityz#=0.0


PositionEntity thing,initialpositionx#,initialpositiony#,initialpositionz# 
PositionEntity planet,0,0,0 ;change these values to change the location of the planet/gravity source



Repeat

dist#=EntityDistance(planet,thing)
If dist#^2>0 Then 
dx#=(EntityX(planet)-EntityX(thing))/dist#
dy#=(EntityY(planet)-EntityY(thing))/dist#
dz#=(EntityZ(planet)-EntityZ(thing))/dist#

accelerationx#=dx#*GravityStrength#/(dist#^2)
accelerationy#=dy#*GravityStrength#/(dist#^2)
accelerationz#=dz#*GravityStrength#/(dist#/2)

velocityx#=velocityx#+accelerationx#
velocityy#=velocityy#+accelerationy#
velocityz#=velocityz#+accelerationz#

EndIf 

TranslateEntity thing,velocityx,velocityy,velocityz

UpdateWorld
RenderWorld
Flip

If KeyDown(200) Then MoveEntity camera,0,0,1
If KeyDown(208) Then MoveEntity camera,0,0,-1
Until KeyDown(1)
FreeEntity camera
FreeEntity planet
FreeEntity thing
End



Try changing the gravity strength and initial positions and velocities.


lo-tekk(Posted 2005) [#4]
Here is a sort of black hole thing:
Graphics3D 800,600

SetBuffer BackBuffer()

camera	= CreateCamera()
light     = CreateLight()
player	= CreateCube()
center	= CreateSphere()	

PositionEntity camera,0,100,0
PointEntity camera, center
PositionEntity player,50,0,50
EntityParent player, center

While Not KeyHit(1)

	speed# = speed# + .0075

	
	PointEntity player, center
	MoveEntity player,0,0,.05
	TurnEntity center,0,speed,0

 

RenderWorld
UpdateWorld
Flip

Wend 


------------------------
www.moonworx.de


Rubiks14(Posted 2005) [#5]
thanks for the replies you guys they helped