cartman Posted May 6, 2016 Share Posted May 6, 2016 Hi guys, i've been scratching my head the past 5 hours, couldn't get past this Step1: Basically, i have a cube rotating along the x-axis: http://www.babylonjs-playground.com/#H7V1D#19 Step2: I want that same cube, to pivot around the origin: http://www.babylonjs-playground.com/#H7V1D#18 The problem is, in Step2, the cube isn't rotating (along it's x-axis) like in Step1. I guess my question is, how do I combine both Step1 and Step2? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 6, 2016 Share Posted May 6, 2016 Hi cartman! http://www.babylonjs-playground.com/#H7V1D#20 There is one way of doing it. CurrentMesh is parented to the y-rotating gizmo box in line 35. This causes currentMesh to get its position changed the rotating gizmo (currentMesh appears to "orbit" the gizmo). Meantime, currentMesh is still rotating on its x-axis... line 48. The gizmo is rotated in line 50. I'm sure it can be done without a parenting gizmo, but maybe the gizmo is the easiest way. If you want, you can make the gizmo invisible with line 33, and you could also use a plane (not box) for gizmo... to reduce scene size a bit. Okay, I hope this helps. Stay in touch. cartman 1 Quote Link to comment Share on other sites More sharing options...
cartman Posted May 6, 2016 Author Share Posted May 6, 2016 @Wingnut thanks, but it's not working as I intended. I'm looking for the cube to rotate on it's x-axis, while the cube pivots around the origin (0,0,0). Here's a more concrete example i'm trying to build. The rear (right side) wheel should keep spinning, while the car pivots around origin. See this animated gif too: http://recordit.co/yYYDHDaPHZ The playground code you wrote, gave a different kind of rotation (http://g.recordit.co/UV1bNv998X.gif) - it looks twisted... Any ideas? Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted May 6, 2016 Share Posted May 6, 2016 @cartman mesh.rotation uses the pivot i don't think there are any easy-fixes. custom rotation around the pivot point would probably be your best bet.. Quote Link to comment Share on other sites More sharing options...
cartman Posted May 6, 2016 Author Share Posted May 6, 2016 @aWeirdo thanks, but i don't quite understand. can you post a playground example? @Wingnut's solution http://www.babylonjs-playground.com/#H7V1D#20 doesn't have setPivotMatrix activated. It depends on the parent (gizmo) rotating along its y-axis, while currentMesh rotates along its x-axis. It's not the same result, as a car wheel pivoting. I'll keep experimenting, thank you. Any ideas are welcome! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 6, 2016 Share Posted May 6, 2016 http://www.babylonjs-playground.com/#H7V1D#22 Does that look better? I needed to align the blue wheel box... with the gizmo.... by adjusting the x-factor in line 38, and then rotate the blue box around the Z axis and not the X axis. Here's another fun one... http://www.babylonjs-playground.com/#H7V1D#23 Sometimes, BJS mesh are not created in the proper orientation for your project. The cylinder (wheel) was such a case. Lines 39 and 40 fixed that. This system might dictate that there would be 3 invisible boxes inside the car. First, a primary parent gizmo for the car... let's pretend it is named carGizmo. There would also be a frontAxleGizmo and backAxleGizmo. They are both parented to carGizmo. You might even think about 5 total gizmos. One for the carGizmo, and then one for each wheel. All four wheelGizmo would be parented to carGizmo. Perhaps more gizmos... for trunk, hood, and door opening/closing. Maybe another for the steering wheel. Electric side mirrors? Two more. Gizmos are similar to invisible puppet strings, eh? A gizmo-per-wheel... would make it easier to steer the front wheels, yet keep them rotating on their Z-axis (rolling). *shrug* Just some ideas... not sure if they are good/wise ideas. jerome, aWeirdo and cartman 3 Quote Link to comment Share on other sites More sharing options...
cartman Posted May 6, 2016 Author Share Posted May 6, 2016 @Wingnut thank you! Works great, here's an animated gif of the car turning left/right http://recordit.co/xpHzKYPeYn Made my day Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 6, 2016 Share Posted May 6, 2016 Excellent! Very nice. Glad I could help. Help another when you get a chance. And... um... are you continuing work on your car? Keep us updated, please. That looks fun! In fact, talk talk talk right now, if you wish. Tell us about you and your projects, right here, if you want-to. What's your story, if you don't mind me asking? Where do you live (if I may ask)? Do you have a website that tells about you and your dreams? I would visit it. GameMonetize 1 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.
Note: Your post will require moderator approval before it will be visible.