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 / [Tier 1] Trouble with FixObjectToObject()

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 18th Sep 2017 17:42
I'm trying to drag stuff around in VR space, using FixObjectToObject()

The command lets an objects position and rotation be relative to another object, instead of being relative to the world. So if the object is positioned slightly above ground level, the object will suddenly be placed slightly above the parent object, with "above" being a direction determined by the parent objects rotation.

Getting the fixed object to keep its original world position is a bit tricky. I tried this:

old_pos_X = GetObjectX (vBox)
old_pos_Y = GetObjectY (vBox)
old_pos_Z = GetObjectZ (vBox)
FixObjectToObject( vBox, leftControllerObject )
SetObjectPosition( vBox, old_pos_X - GetObjectX (leftControllerObject), old_pos_Y - GetObjectY (leftControllerObject), old_pos_Z - GetObjectZ (leftControllerObject))

And this works as long as leftControllerObject is not rotated at all. But as soon as it is rotated, things gets weird.

I tried my best, but I'm truly lost. Any clues to where to go from here?



PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Sep 2017 18:39
I cant speak for VR but I have made lots of use of FixObjectToObject in my 3D editor without any problems, as I understand you fix objects after setting there world position and then only set the position/rotation of the parent object, setting the child object after fixing to a object does produce weird results.
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 19th Sep 2017 12:55

Maybe we are talking about two radically different scenarios?

You are talking about fixing an objects position before the actual game, when the object is at a blank state, with its position at 0,0,0 and its rotation at 0,0,0
I'm talking about fixing an object to another in the middle of the game, when both objects rotation and position will be weird numbers.

I tried making a small comic strip illustrating what happens when an object gets fixed to another object. It's all awful logical, but I'm not sure how to use it.

Attachments

Login to view attachments
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 19th Sep 2017 15:21 Edited at: 19th Sep 2017 15:22
The proper way to do it would be to transform by the inverse of the parent object's rotation and position, then transform by the child object's rotation and position. It's a bit like vector subtraction, where you go backwards down one vector then forwards along the other to get the vector pointing from one to the other. The math involved is quite heavy so you can cheat and use AGK's object transforms to do it for you
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 19th Sep 2017 20:01

Thanks Paul, that one worked right out of the box! And unfixing it with FixObjectToObject(2,0) while keeping the spatial position is pretty easy using stuff like GetObjectWorldX(2) and GetObjectWorldAngleX(2)

... Actually, this opens for quite a lot of possibilities. I'm ever so slightly blown away.

Login to post a reply

Server time is: 2024-04-25 03:15:40
Your offset time is: 2024-04-25 03:15:40