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 Classic Chat / moving objects according to camera orientation

Author
Message
ruckertheron
8
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 8th Sep 2019 16:27
How would I move an object in the direction of my choice no matter what angle the camera is? I know theres a formula but I can't seem to come up with it. Like I move objects according to X and Z-axis but when the camera angle changes the directions change as well...
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 8th Sep 2019 17:52 Edited at: 8th Sep 2019 17:56
MoveObjectLocalX( objID, amount )
MoveObjectLocalY( objID, amount )
MoveObjectLocalZ( objID, amount )

I'm not sure if that's what you want, though...
These commands move an object in any direction, no matter which direction they were facing...


PSY LABS Games
Coders don't die, they just gosub without return
ruckertheron
8
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 9th Sep 2019 22:32


In this example I have a circle that represents the object I'm trying to move. The rectangle that circle is in is an overhead camera view looking down. When I move the object on its X-axis or Z-axis, it consistently moves the same way. The blue arrow is where I want the object to move when pressing the 'up key'. Figure 1 works because the camera is set but Figure 2 is adjusted 90 degrees and this changes "up" to northeast... is there a formula based on the camera angle to push the object up regardless of what angle the camera is facing?

Attachments

Login to view attachments
SFSW
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 10th Sep 2019 00:02 Edited at: 10th Sep 2019 00:03
There are a couple of ways to do that. You can use hidden guide objects to keep track of rotation offsets and/or alignments. But I'd recommend some simpler approaches if you are using a static overhead perspective that doesn't shift around in terms of pitch (so you are looking down on your object from above on the Y plane all the time).

Lets say your camera has tilted to the left as in your example image above, maybe 45 degrees. You can keep track of the Y (yaw) axis rotation for the camera in a variable, then apply that as an offset to the object before moving it:



If you're not using variables to keep track of the camera's orientation, you can just align it directly:

Login to post a reply

Server time is: 2024-11-22 17:03:36
Your offset time is: 2024-11-22 17:03:36