practicing01 Posted May 19, 2016 Share Posted May 19, 2016 Hello, I'm trying to orient an object based on a raycast result transformation. The following isn't working. Any help would be appreciated. %rayResult = %obj.doRaycast(10000.0, %rayMask); %objTarget = firstWord(%rayResult); %objPos = getWords(%rayResult, 1, 3); %objDir = getWords(%rayResult, 4, 6); %transform = MatrixCreateFromEuler(%objDir); %box_.setTransform(%transform); %box_.position = %objPos; Quote Link to comment Share on other sites More sharing options...
irei1as Posted May 19, 2016 Share Posted May 19, 2016 I can't find the function "doRaycast" in my build so I'm going to assume you're using the one defined inhttps://www.garagegames.com/community/forums/viewthread/118723(You may want to check the console for "Unknown command doRaycast" error if you're not using that).Your code seems correct.I would try %rayResult = %obj.doRaycast(10000.0, %rayMask); %objTarget = firstWord(%rayResult); %objPos = getWords(%rayResult, 1, 3); %objDir = getWords(%rayResult, 4, 6); %transform = MatrixCreate(%objPos,%objDir); %box_.setTransform(%transform); But that's basicalliy the same.For testing you may want to also add to thatecho("Ray result=" SPC %rayResult);To be sure the raycast was correct. Quote Link to comment Share on other sites More sharing options...
practicing01 Posted May 20, 2016 Author Share Posted May 20, 2016 I'm using the ShapeBase doRaycast. This is the result (wrong) http://img.ctrlv.in/img/16/05/20/573e5a8450fdf.png Quote Link to comment Share on other sites More sharing options...
irei1as Posted May 20, 2016 Share Posted May 20, 2016 Alright, the code should work as this: %rayResult = %obj.doRaycast(10000.0, %rayMask); %objTarget = firstWord(%rayResult); %objPos = getWords(%rayResult, 1, 3); %objDir = getWords(%rayResult, 4, 6); %mat_rotx = MatrixCreateFromEuler( mAtan( mSqrt( %objDir.x*%objDir.x + %objDir.y*%objDir.y), %objDir.z) SPC "0 0"); //%mat_localzrot = MatrixCreateFromEuler("0 0" SPC %localzrot); //%mat_rotx = MatrixMultiply(%mat_rotx,%mat_localzrot); %mat_rotz = MatrixCreateFromEuler("0 0" SPC mAtan(%objDir.x,%objDir.y)); %transform = MatrixMultiply(%mat_rotz,%mat_rotx); %box_.setTransform(%transform); %box_.position = %objPos; If you want to rotate the %box_ in the local z axis then remove the commenting and define %localzrot as the radian angle to rotate. Quote Link to comment Share on other sites More sharing options...
practicing01 Posted May 21, 2016 Author Share Posted May 21, 2016 Thanks irei1as! It worked. The code will probably help others in the future as well. This expert-level math is beyond lots of people. Game development requires engineer-level knowledge in a lot of aspects but if this engine wants to be newbie-friendly, rotations (other areas as well) need more helper functions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.