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.

DarkBASIC Discussion / gravity pulling on an object at any given angle

Author
Message
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 31st May 2003 10:39 Edited at: 31st May 2003 10:41
the question was asked here, and i know forum spanning is bad^_^ but I figured there are capable people here that don't necessarily post there.. so here is the link.. feel free to post here or there
http://www.realgametools.net/forums/index.php?board=2&action=display&threadid=15728&start=0

and the question is this
I've got a 3d object that needs to be pulled down in relation to that object's angle.. IE..if its on it's side then it needs to be pulled by gravity on a horizontal axis...

How can I implement this properly? Thanks



The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 31st May 2003 18:17
I don't quite get what you mean - if you mean that you want the object to move backwards, use MOVE OBJECT num,-1 to make an object move backwards.

You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 1st Jun 2003 04:03 Edited at: 1st Jun 2003 08:58
well .. mm er ..

Some objects falling turn to point in the direction of the fall. But first you will need to add gravity for pitch, where gravity actions will relate to the sine of the x angle. ( increasing as the angle steepens and + - according to slope.)
To be accurate for pitching, work out the scale of gravitational acceleration for your 3d 'world' .
ie. the DB units to be added to speed every frame to make an acceleration of a 'scale' 9.8 meters,every second
Multiply this figure by the sine of the object x angle and ADD IT TO YOUR SPEED VARIABLE. The constant addition every loop is what causes the proper 'acceleration'.

YOu will need drag (objectdragcoeficient * speed* speed ) to limit uncontrollable acceleration.

---------------------------------

EDIT and Panic
-- as i realise this is possibly for a space or flight sim rather than a car ..

If this is may be for a space sim you may have to totally modify your rotations .
Currently, if you turn 90 degrees left your mouse x control is now z or roll control. You will need a 'free flight' style control instead.

However, assuming you limit your object and it is going to stay pointing fairly closely down the z axis of the world the rotations will be okay.
If it is actually interacting with air ?? then the above speed reaction based on the sine of the pitch will occur.

If it is in space and there is 'thrust' forward it will react much the same also with speed changes.

But if the object is in space with no thrust forwards, it will be in zero g free fall.
Any temporary rotation thrust changes will act around the centre of gravity and their will be rotation , but little other change in position.

Perhaps you are wanting the effect as with an aircraft ?.. when a plane is rolled over the lift reduces and the gravity - if the pilot does nothing - causes falling altitude and the plane then slowly angles and 'slips' around to point along the direction of the turned and downward vector.

is this object 'hovering' on an invisible upthrust against gravity.?
if so it will do something similar.. it will lose altitude proportionally to the sine of the roll angle - and drift sideways by the sine also.

here's how to put that in your code :-

rem out the present three -
positionX# = NEWXVALUE(positionX#,Zangle#,2) parts and substitute --

upthrust#= .2: ` make this a power level variable?

gravity#= abs(sin(zangle#)*.4)+ abs( sin(xangle#)*.4)+ abs( sin(yangle#)*.4)
positionY# = positionY# + upthrust# - gravity#

positionx#=positionx#- sin(zangle#)* upthrust#
positionZ#=positionZ# + sin(xangle#)* upthrust#

You can rem out the last two lines which are the 'drift' resulting from displaced upthrust.

So it goes rather like a helicopter. The more you tilt forward the faster forward you go.
Alter the upthrust to see effect.

I haven't bothered to include y rotation using newxvalue etc since the present rotations are not really suitable for all direction flight response.

A simplified way of changing this would be to substitute this code for the xrotate object etc.

`update angles
rotate object 1,0,0,0
turn object right 1 ,Yangle#
pitch object up 1, Xangle#
roll object left 1, Zangle#

This can't do 'free flight' but it is can rotate better when heading in different world directions. The odd thing is that the z drift is reversed this way, so you need to change the sign.
It is left for you to convert the 'drift' positions for different directions in the world using newx etc.

And i am still not clear what it is you want, but having started i wanted to come up with something !!

cheers muddleglum.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 1st Jun 2003 09:40
ok... think of it as a spaceship with some sort of gravity well sitting on the bottom... if the ships is upside down...the gravity well will cause the ship to lift up...if the gravity well is on the bottom...it will cause the ship to fall down...if the ship is on it's left side it will move towards the right...and vice versa..

normal downwards gravity is not figured in at the moment and will be easy for me to implement on my own..so no one needs to worry about that.. I hope i made it a little more clear :-s

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 1st Jun 2003 13:07
So you want your ship to move towards something ,without rotating the ship?

This might work:



You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 1st Jun 2003 14:44
aahh thats a better explanation !

David89's idea could work - if you position a gravity well object there first .

But, depending on what you want, you may still have the problem of rotating your ship to all angles .. and since full rotation would mean using ' free flight' commands it would also be possible to implement your gravity well effect thus ..

pitch object down ship, 90
move object er.. 'gravity well effect '
pitch object up ship, 90

this will work at any angle whatsoever.
It might be interesting to have the ''gravity well effect' amount of move as an acceleration ( as for a gravity), it's amount added to per frame, and limited by some sort of spacedrag!

then i guess you could get downwards gravity by simple y coord displacement.

whatever .. good luck.
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 1st Jun 2003 21:57
as a spaceship with some sort of gravity well sitting on the bottom

note that there's no gravity (or VERY few - not notable) in space

[href]www.bernardfrancois.com[/href]
Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 2nd Jun 2003 01:59 Edited at: 2nd Jun 2003 02:22
ah well, here you go .. the method i suggested works as you intended. Note it uses the alternative rotation method and works in all world directions now.
A bit of inertia on the controls would be a nice addition.

(And notice the use of variables for the object positions .. doesn't anyone else get very tired of typing out object positon x(1) blah and blah and going off the side of the screen ?)

have fun.
muddleglum

-------------------------

SYNC ON
AUTOCAM OFF
HIDE MOUSE

` Create the player & Scenery
MAKE OBJECT BOX 1,10,10,40

MAKE MATRIX 1,1000,1000,30,30
POSITION MATRIX 1, -500,0,-500

` Set the timer interval & the players initial speed & initial Player co-ords
positionX# = 0 : positionY# = 10 : positionZ# = 0

DO
turnthrust# = turnthrust# * 0.85

IF LEFTKEY() = 1
turnthrust# = turnthrust# -1
ENDIF
IF RIGHTKEY() = 1
turnthrust# = turnthrust# + 1
ENDIF
if inkey$()="r" then position object 1,0,0,0
`calculate the angles
Xangle# = WRAPVALUE(Xangle# + (MOUSEMOVEY()/2))
Yangle# = WRAPVALUE(Yangle# + turnthrust#)
Zangle# = WRAPVALUE(Zangle# + (MOUSEMOVEX()/2))


`
`update angles
rotate object 1,0,0,0
turn object right 1 ,Yangle#
pitch object up 1, Xangle#
roll object left 1, Zangle#

`!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!!**!*!*!
`right here is where we do the the gravity well effect...

pitch object down 1, 90
move object 1,2
pitch object up 1,90
ex#= object position x(1)
why#= object position y(1)
zed#= object position z(1)
if why# < 0 then position object 1, ex#,0,zed#

`update camera
SET CAMERA TO FOLLOW ex#, why#,zed#, Yangle#, 100, why# + 40, 2,0
POINT CAMERA ex#,why#,zed#

SYNC
LOOP

` ----------------------------------------------
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 2nd Jun 2003 07:02
oh man you hit the nail on the head!! Thanks!

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 2nd Jun 2003 08:35
ok.ok..it's almost there..lol..but the turn object left doesnt quite work how it is supposed to... cuz when you turn left the object should take into account it's current rotation and turn left...it's so hard to explain..grrrrrrr...

um... like... when the object is standing vertical... and i turn left... it spins as if I were rolling the object left... instead spinning on the object y axis(not the world Y axis)... i dont know if that makes any sense

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 2nd Jun 2003 12:02
Is this any closer to what you wanted?



Once I was but the learner,
now, I am the Master.
eGuy
22
Years of Service
User Offline
Joined: 24th Jan 2003
Location:
Posted: 2nd Jun 2003 20:54
Here's a quick attempt I made a while back to implement actual gravity using the physics equations that should work. The object angles are irrelevant because gravity works in the direction of the mass regardless of how your plane or whatever is oriented. I haven't fully tested this yet or implemented inertia and such, but it should at least get you started.

In order to see anything move you'll probably have to play with the input variables, I just grabbed random values out of the air.

Muddleglum
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: New Zealand
Posted: 2nd Jun 2003 23:17 Edited at: 2nd Jun 2003 23:20
good grief .. this is getting involved .. back two posts ..
yes Jerico2day , I think i see what you mean.
You can easily get the rotations you want if you use free flight commands -- as on the code with this post.

BUT THE PROBLEM IS THIS ... try it first and just be sure that the object is moving and rotating as you intended .
You will see though, that the CAMERA is simply pointing from a fixed angle.
Okay .. rem out the line ' rotate camera 0,0,0' -- and the camera will align with the object's y direction.

When level it will look okay, but as soon as the pitch increases you will see that the object appears to twist about oddly. The steeper , the more so.
This is not an error -- It just looks bad !! You can see the y axis of the turning object is indeed aligned with the camera. It's just an invitable result of using the rotations you want. If you turn the object when pitched up , it's direction also changes,( hence why i gave you the earlier version) .

So before going further you will have to tell us how exactly you want the camera to follow the object in terms of angles. Is the camera always to be level with the matrix ? .. in which case some cunning follow code will be needed to avoid thsi weird look -- if it is even possible.
Or can it follow aligned to the object as on the second camera view? Just un-rem it and it will work.

Or do you want the camera to only change y angle when the object is level or near level?
The problem is how you chose when exactly .. and how do you avoid 'jumps'. I tried a few sine/cos experiments and then decided it was going to take a bit of time and thought - or luck.
Also tried it on the previous code . It looked quite good but the roll and turn controls reversed themselves once it had 'turned' while 'pitched' in relation to the world.

It may all involve a bit of a re-think.
If this is for one of those coordination type games where say objects are directed into positions or gaps or such ?? that will alter the view needed.

Or is it more a free flying space ship, like an aircraft flying and the gravity well as just an extra.

time for a break .. here's the latest code .

--------------------------


SYNC ON
AUTOCAM OFF
HIDE MOUSE

` Create the player & Scenery
MAKE OBJECT BOX 1,20,5,10
make object cone 2,10
scale object 2,100,100,400
pitch object down 2,90
fix object pivot 2
glue object to limb 2,1,0

MAKE MATRIX 1,1000,1000,30,30
POSITION MATRIX 1, -500,0,-500


DO

if inkey$()="r" then position object 1,0,0,0: rotate object 1,0,0,0: direction#=0

IF LEFTKEY() = 1 then turnthrust# = turnthrust#+1
IF RIGHTKEY() = 1 then turnthrust# = turnthrust#-1
turnthrust# = turnthrust# * 0.85

turn object left 1, turnthrust#
pitch object up 1, (MOUSEMOVEy()/2)
roll object left 1,(MOUSEMOVEx()/2)

`!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!!**!*!*!
`here is where we do the the gravity well effect...
pitch object down 1, 90
move object 1,2
pitch object up 1,90

ex#= object position x(1)
why#= object position y(1)
zed#= object position z(1)
if why# < 0 then position object 1, ex#,0,zed#

`update camera first version.
position camera ex#, why#+40,zed#
rotate camera 0,limb direction y(1,0),0
rotate camera 0,0,0: REM this is the bit to rem out
move camera -100
POINT CAMERA ex#,why#,zed#

`update camera second version.
remstart
position camera ex#, why#,zed#
set camera to object orientation 1
pitch camera down 20
move camera -100
remend

SYNC
LOOP
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 2nd Jun 2003 23:48 Edited at: 3rd Jun 2003 00:55
Muddleglum you are truely the 3d master^_^ That's it exactly you are awesome man..
[edit]
http://members.lycos.co.uk/timesaga/forum/viewtopic.php?t=46

As for my project, read up on it here and keep checking back if it interests you as new info and screenies will be added, and also feel free to ask questions or give comments/suggestions^_^

And thanks to everybody who helped me I really appreciate it!

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/

Login to post a reply

Server time is: 2025-06-18 05:09:57
Your offset time is: 2025-06-18 05:09:57