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.

3 Dimensional Chat / How to rotate a 3d physics object to a target rotation?

Author
Message
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 17th May 2020 11:33
Hello!

Having fun with AGKVR.

Moving a physics object gradually to a desired position is working perfectly. (Like a Jedi using the force )



However I'm having trouble rotating the physics object to a desired angle.

I seem to encounter gimbal lock issues and the object rotation begins to twitch erratically.

Any ideas on how to do it?



If at first you don\'t succeed, sky-diving isn\'t for you.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th May 2020 21:27
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 17th May 2020 21:50
I was using SetObject3DPhysicsAngularVelocity() and seeing erratic rotation behaviour. I am obviously doing it wrong but I'm having trouble finding any information about how to do it right.

In the VR example projects, they are using contact and joints, which is fine if you don't want the object to snap to a specific rotation when it reaches your hand (such as a ball) but that doesn't suit something like a sword.
If at first you don\'t succeed, sky-diving isn\'t for you.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th May 2020 21:40
Do you have some sample code?
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 18th May 2020 22:20 Edited at: 18th May 2020 23:54
This is what I have so far. It seems to work in limited ranges, but goes bananas at certain angles.

This function is supposed to apply angular force to an object so that it will eventually reach the same orientation as the target_obj

Thanks



If at first you don\'t succeed, sky-diving isn\'t for you.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th May 2020 00:22
Try SetObject3DPhysicsCanSleep(obj, 0)
You will need to check the rotation values are close enough in order to stop the rotation when they match
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 19th May 2020 00:36 Edited at: 19th May 2020 00:37
Thanks, but perhaps this video will illustrate better the issue I'm having


If at first you don\'t succeed, sky-diving isn\'t for you.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th May 2020 01:15
So this is a different problem then?
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 19th May 2020 10:06
The desired result is that the object (rubiks cube) matches the orientation of the hand (the yellow box).

The problem is that it doesn't always match the orientation of the hand.

So I am obviously doing something wrong and would like some help figuring it out.

¯\_(ツ)_/¯

If at first you don\'t succeed, sky-diving isn\'t for you.
Anthony Brian Cox
7
Years of Service
User Offline
Joined: 29th Dec 2016
Location:
Posted: 19th May 2020 18:30
have you tryed usin a vector 3 from the hand angle (vector3=createvector3(getobjecanglex(ob),(getobjecangley(ob)(getobjecanglez(ob))
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 19th May 2020 18:35
Thanks for taking a look.

Quote: "have you tryed usin a vector 3 from the hand angle (vector3=createvector3(getobjecanglex(ob),(getobjecangley(ob)(getobjecanglez(ob))"


I don't quite understand. Can you elaborate on what you would do with the vector in relation to the code snippet above?
If at first you don\'t succeed, sky-diving isn\'t for you.
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 19th May 2020 23:07 Edited at: 19th May 2020 23:08
Here is a test using Create3DPhysicsFixedJoint() to attach the cube to the hand object.

The hand object is a KinematicBody positioned at the RightController by SetObjectPosition and SetObjectRotation.

I've added the X, Y and Z axis (Red, Green, Blue respectively) so you can see the orientation of the hand.

This appears to be exhibiting the same orientation behaviour as seen in the previous video.

Am I doing something wrong or is there a bug?

If at first you don\'t succeed, sky-diving isn\'t for you.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th May 2020 23:31
I think you will have a problem when you are crossing axis. Like going from 5 to -160 for example.
If the cube is ALWAYS going to match the rotation of the hand object. Maybe make the cube NOT a physics object and simply match the rotations of the Hand.
If you want to do something else, like throw the cube, then you could create a physics body then and apply the appropriate forces.
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 20th May 2020 00:20
Quote: "I think you will have a problem when you are crossing axis. Like going from 5 to -160 for example."


I notice the 6DOFJoint doesn't have this issue. It can swing in all directions quite happily.

Quote: "If the cube is ALWAYS going to match the rotation of the hand object. Maybe make the cube NOT a physics object and simply match the rotations of the Hand.
If you want to do something else, like throw the cube, then you could create a physics body then and apply the appropriate forces."


Yes this is something I tried, and it works, but I wasn't sure if there was a better way. I had tried it so that when you grab a cube it would turn into a Kinematic body, so that I could use SetObjectRotation and still have the held cube affect other physics objects, which works perfectly up until you want to throw it, like you said.

I will implement it this way again and apply forces when the grip is released.

Thanks for the help


If at first you don\'t succeed, sky-diving isn\'t for you.

Login to post a reply

Server time is: 2024-11-17 22:48:09
Your offset time is: 2024-11-17 22:48:09