I’ve imported a mesh using LoadAssetContainer and inserted it into the scene. Now, I couldn’t figure out how I could rotate the mesh. Tried different ways. Couldn’t achieve.
Well, I don’t know what is the “right direction” but you can change parameter values at line 18 in order to rotate the mesh parent.rotate(new BABYLON.Vector3(0, 15, 0), BABYLON.Tools.ToRadians(0)); https://playground.babylonjs.com/#4APS6E#8
Yes, I tried that. Could you see the trunk of the jeep? That’s the back and the back has tail lights - red color. The car now moves forward with the tail lights at the front (which basically means the car is reversing, when accelerating). Could you help me correcting the right direction?
I tried rotating the parent before the mesh linking loop - this allows you to adjust the direction in the scene
` let orientation = 180;
// change orientation to suit the direction of the car
parent.rotation = new BABYLON.Vector3 (
BABYLON.Tools.ToRadians(0),
BABYLON.Tools.ToRadians(orientation),
BABYLON.Tools.ToRadians(0)
)`
I think for a start it would be good to have your locals set correctly on XYZ on your model. Why does your model look back in the first place? Then you can also change your inputs so that ‘forward goes forward’ etc… Finally if you set a parent, and want to act on the children, remember you have to work from your parent (or anchor, in case). But I think the first point here is that the vehicle (mesh) should have its axes set correctly from the start.
Honestly, yes the ‘fix’ works but I would rather urge to set the model correctly. Especially, since this is a vehicle not a house. In essence, it will always remain faulty by default and will require the fix. Knowing that physics are (heavily) involved in a vehicle’s behavior… again, make it right from the start and it will remain right (and also comprehensive)… this would be my advise.
From a traditional 3D perspective, I could depend on the orientation or pivot of the mesh - ultimately children will inherit the transform of the parent. So if a mesh isn’t reset properly, it can hold values in it’s transform matrix that gets multiplied into the parent transform when linked. So @mawa 's suggestion would be where I’d look first.
Since child nodes have their own local coordinate space, it is relative to the parent rather than the world. So the parent transforms applied to an object will only traditionally propagate to the child after being linked. As @labris mentioned, the behaviour that is going on is odd so it would be good to get the physics out of the equation and see what happens before this is triggered with the raw asset so you can rule out this first part.
Let me just add this very personal note to you @mapkbalaji . You realize you picked a hard piece wanting to create a vehicle. Many have tried, in BJS and others (incl. Cyberpunk;), few have succeeded. Yes, it is BJS, yes we can do a lot of things, sometimes with just copy/pasting a bunch of code, but physics and physics for a vehicle remain. I have been working 15y. with the automotive industry and I think I can say that the physics of car are nothing easy to handle. So, I encourage you to continue of course. I believe we need people trying to push the boundaries, also in vehicle handling. May be, pay a visit to the other PGs, try to nurture and next enhance… You have chosen the long way my friend, I wish you GL…truly.
There is also a good way to get rid of all parent/child code part.
You can upload .babylon model into Sandbox and save as GLB file.
Here is node structure of your original .babylon model:
And here is the structure of GLB file:
As you see, there is already root node which is the main transform node for this model, so you don’t need to set it manually with the code.
Thanks @mawa. I’m just trying to create a simple arcade type game, where an object can be moved around the screen to explore the scene. Something like https://bruno-simon.com/. And yea, I’m a newbie in this world, and I wish to go a long way. Just learning to tackle some of the obstacles I face.
@labris Yea, I see that the glb groups the nodes into a root node. But, I’m having problem importing the glb into my scene. It gives an error:
Unable to import meshes from 'url: importMesh of undefined from undefined version: undefined, exporter version: undefinedimportMesh has failed JSON parse
I tried using assetsManager, Append, ImportMesh but all gives the same error. What am I doing wrong?
Cool. Thanks for sharing. Very nice and clean little arcade game and the car behaves pretty well. You certainly can achieve something like that with BJS. Still, it’s not all that simple. Quite a bit of work has been put into this but if you are motivated and with the help of the existing PGs, I guess you can make it Let me/us know when done. I’m sure many people here would like to see more examples of vehicles. Have a great day,