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 / Getting an object to face direction of travel in a 3D environment.

Author
Message
JRNTexas
12
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 29th Jun 2020 17:41
Again, just getting started in App Game Kit Studio and to know how to get an object, in this case a satellite or spaceship to face in the direction of travel, especially if that direction vaires, as in turning the spaceship or the satellite following an orbit (which I have it doing already via cos & sin).

Any code snippets, tutorials, reading on the subject would be appreciated.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 6th Jul 2020 23:02 Edited at: 6th Jul 2020 23:26
Late response so maybe you have this solved but....

One trick I use to get angle info relative to another object is to set a small invisible cube CreateObjectBox(cubechild,2,2,2) as a child of the object (ship) with FixObjectToObject(cubechild,ship) and make sure to use SetObjectposition(cubechild,0,0,0) and SetObjectRotation(cubechild,0,0,0) which will place a child exactly where the parent is with the same rotation. That is for pre-loop setup.

In the loop, something like SetObjectLookAt(cubechild,GetObjectX(planet),GetObjectY(planet),GetObjectZ(planet),GetObjectAngleZ(ship)).
Now if you read the angle of the child, you can use it as an offset for the ship. Rotate the ship to keep the child near 90 degrees.

Not sure if that's the hard way to do it.

Or for orbit, just get the ship to look at planet then rotate 90 on the Y every time through the loop.

If you search the forum for "radar" you can find some of my code but I've not done orbital stuff yet.

PS- as I'm not that clever with math, I try to find "other ways" to get the job done.
Never play leap frog with a unicorn.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 7th Jul 2020 00:26
I just thought of another bodgy dodgy way.

Drop a box at your ships current location, wait till the ship moves, then tell the box to look at the ship and move the box forward a little further than the ship has moved, to place the box in front of where the ship is heading. Then just tell the ship to look at the box.

I am assuming you are moving the ship without caring what direction it is facing which is a different way to do it. We would normally just move an object on it's Z axis (forward) with MoveObjectLocalZ(ship,1), 1 being the speed. The rotation would then be based on the ship speed and the distance from the center of the orbit (planet).
Never play leap frog with a unicorn.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Jul 2020 03:04
if you want an object to face another object
SetObjectLookAt( objID, x, y, z, roll )

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
JRNTexas
12
Years of Service
User Offline
Joined: 24th May 2011
Location: Austin, Texas
Posted: 8th Jul 2020 03:00
Thanks guys! This helps a bunch!

Login to post a reply

Server time is: 2024-03-29 06:31:59
Your offset time is: 2024-03-29 06:31:59