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 Studio Chat / 3D Physics - Calculate new velocity vector of a moving object

Author
Message
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 29th Oct 2019 13:02
Hi all,

I have a moving 3D object, I can rotate the object whilst it is moving. I want to apply a force to the object in the direction it is facing when rotated. The new direction and velocity will be the resultant calculation of the original direction and velocity effected by the new force and its angle. Mmmmm, hope I have explained the problem. I have a 3D moon lander travelling in a straight line along its Z axis. I rotate the lander as it is moving along its path, the direction of the path obviously does not change. I want to apply a thrust in the direction the lander is now facing to change its direction.

I cannot find a 3D 'Impulse' force command that make the effect realistic and so I guess a new Velocity Vector must be calculated to apply to the lander using its current direction and velocity and the new rotated angle of the lander plus the new thrust.

Any ideas Amigos?

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 29th Oct 2019 14:29
I would suggest looking at one of the kart physics thread they have full source
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 29th Oct 2019 14:42
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Oct 2019 20:03
You can use float GetObject3DPhysicsLinearVelocityX/Y/Z()
If you calculate the length from (0,0,0) to those 3 values then you have the objects linear velocity.
This does not take into account it's angular velocity (torque or spin i think)
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 30th Oct 2019 10:28
Thank You. I have figured it out!

SetObject3DPhysicsLinearVelocity(apollo,(sin(GetObjectAngleY(apollo))),0,(cos(GetObjectAngleY(apollo))),thrust#) - Simply Pythag formular

As I am only trying to simulate the landers direction and velocity in the X and Z axis after applying thrust in the direction the lander is facing the above works great. (Y axis gives me lander angle and adjustment of height above the surface)

So sorted and looking very cool...


Attachments

Login to view attachments
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 2nd Nov 2019 14:45
@Rudders

This is looking awesome. You should put up a vid/gif/demo. Very curious to see what it behaves like.
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 2nd Nov 2019 18:12
Hi Rick,

Early days for this project but it runs very smooth at the mo with very realistic movement. I plan to turn this into a full game with instruments and different stages of approach, descent & landing, then return to orbit... We will see. I will post a video next week of how it looks and feels so far.

Thanks for the comments.

Paul
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 4th Nov 2019 11:14
Hi All that are interested...

My previous post showing the calculation of vector velocity for a 3D object is not completely correct and needs some work... I have been applying a thrust# value that increases the more often you hit a key, this is incorrect as you should apply a constant thrust# value each key press and increase the velocity accordingly. I have adjusted the code and things feel much more realistic. I still have to figure out vectored velocity when thrust# is applied when the object is facing a different angle.

Will update soon.

Cheers Paul

Login to post a reply

Server time is: 2024-04-18 01:55:35
Your offset time is: 2024-04-18 01:55:35