Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to change the centre of mass location? #66

Open
Snky opened this issue Aug 8, 2023 · 10 comments
Open

Question: How to change the centre of mass location? #66

Snky opened this issue Aug 8, 2023 · 10 comments

Comments

@Snky
Copy link

Snky commented Aug 8, 2023

As the title suggests. It's a 2 in 1 question, I want to separate rotation location from mass location.

If I make a model in blender, let's say a car:
The very front of the car is at 0, 0, 0
The very back of the car is at 0, 0, 100

In terms of rotation, I am happy with this, if I did Rotate(0, 1, 0), the car will spin from 0, 0, 0
In terms of mass, this is horrible, because now the back end of the car is up in the air, and the focus point of the mass is 0, 0, 0 - not the centre of the car, how can I adjust either the mass location, OR:

If I were to make the pivot point of the car in Blender to be the middle of the car, then how do I rotate the car from the very front, and not the centre?

@Dev-MarkoF
Copy link

Unfortunatly if i understand it correctly it is not possible to change the center of mass in OIMO.
There seems to be an old enhancement which describes what you trying to achieve. issue #28

Unfortunatly it seems @saharan does not look frequently into issues anymore, since the engine basically works fine.
Be aware that car physics can be wonky since it's a heavy object, due to a bug only happening on heavy objects issue #60

I use a workaround to achieve those kinda things with multiple rigidbodies and connecting them with welding joints.
(meaning a joint that allows no movement/rotation between the bodies, basically connecting them to one), In that case you can make the car heavier at the front (which is realistic since the engine is the heaviest part) and then a middle and rear rigidbody.

@Snky
Copy link
Author

Snky commented Aug 10, 2023

I think you are understanding correctly, I'm not very good with GitHub, you say there's an enhancement, are you able to drop it here or contact me outside of GitHub, it's quite an important thing I want. I read about offsetting the shapes, but if I do that, I also change the location the rotation starts from? I want that to be separate from the centre of mass location. Please help if you can.

@makc
Copy link

makc commented Aug 10, 2023

you say there's an enhancement

@Snky I think it means the issue label - it was labelled an "enhancement", meaning this is a nice-to-have-in-the-future thing that is not available right now.

@Dev-MarkoF
Copy link

Yeah as @makc said, there is a feature that is in planning but was never done so far.
This engine works fine but you probably won't see the issues labeled "enhancement" implemented in the near future, so if you really need some very sophisticated features you should look into ammo which is a "port" of the bullet physics engine, which is a industry proven c++ physics engine.

OIMO can do pretty much everything but you have to combine certain techniques to achieve them.
OIMO for example does not have a readily available "car" body like some engines, e.g. Bullet, do, but you can combine joints/raycasts with bodies to achieve it by yourself.

I mentioned a workaround, which i found, because i'm using oimo in some projects, that are somewhat realisitic.
Use multiple rigidbodies and weld them together through joints, a joint has degrees of freedom for rotation/movement, if you set them to 0 on the general joint the objects are held together.
I can't offer more than that, since the inner workings of OIMO are too much of a mystery too me to improve on it myself (i only managed to implement a trigger collider type in my fork).
This workaround is also the way you can create concave shapes since the engine only works with convex shapes.

This workaround resembles reality in some way, since a car is "one" entity in the broader sence, but consists of several others like a front, middle and rear, which by themselves would consist of parts.
You can rotate the front of the car to simulate steering and since the middle and rear are attached to it, through the "unmoving" but linking joint, they rotate with, while also acting like the front of the car is heavier than the back.

In general the idea is:
To have a body where you rotate around, when you want to steer, and multiple bodies that have their center of mass where OIMO wants it to be but change the actual "center of mass" of the combined "body" by changing masses of each body until you're satisfied.
Like imagine multiple water balloons on a stick, you can swing from any balloon but the "center of mass" is defined by all balloons and you could fill each balloon with variable amount of water to change the center.

@Snky Snky closed this as completed Aug 14, 2023
@Snky
Copy link
Author

Snky commented Aug 14, 2023

I will try weld joints, sad that there isn't an easier solution available without creating more bodies, splitting the shapes up.. my shapes are generated based on .obj vertices / faces.

Off topic (not sure how else to contact you atm):
I have a similar isSensor to your isTrigger, I'm currently trying your isTrigger setup, but when I set _rb.isTrigger = true (on one object), the two objects are still colliding, isn't the object supposed to pass through without colliding and just send an event?

Using my old way (works):
if ((_b1._isSensor == false && _b2._isSensor == false) && (_s1._isSensor == false && _s2._isSensor == false)
One line above:
if (_touching) {
Worked for me, but I feel like overall you may know what you're doing better than me, can you assist?

@Snky
Copy link
Author

Snky commented Aug 14, 2023

Oops, accidentally closed.

@Snky Snky reopened this Aug 14, 2023
@Dev-MarkoF
Copy link

It's unfortunate, but i think OIMO get's no significant updates, java/-typescript 3D physics engines seem to be rare and seldomly updated in general. There is a version of the old cannon-js physics that is updated relatively frequently cannon-es. Cannon in general is a very robust engine, but i personally found OIMO first and had an easier time doing the things i needed, so i stayed with OIMO and actively try to answer questions about it, but i'm not associated with it and do not have contact with the developer.

Yeah trigger was the only thing that was relatively simple to implement, OIMO is well not documented enough for someone to take over easily.
I started to integrate a terrain collider, but i have not figured out collisions yet (probably never will, as i'm short on time), only raycasts. Currently trying to develop my own physics engine to get more of an understanding how OIMO works.

Unless i have a bug in it, there is nothing to be done than for usage, just setting "_isTrigger" on the body, and it works in the Game Engine where i implemented OIMO
(my build i used there definetly works, since it's used daily in education, but this is only in my fork/build, i never made a pull request).

My _isTrigger setup is handling collision the normal way until the moment where the manifold is given to the solver,
then it's ignored so the solver thinks there was no collision happening but everything else beforehand happens, so you can get exact points/speed where it triggered etc.
On the way there is a "isTriggering" set, so i can send OnTriggerEnter and OnTriggerExit events.

For that i have changes in World.hx, ContactManager.hx, ContactCallback.hx, Contact.hx, RigidBody.hx and ContactConstraint.hx, if you want to take a look at it.

@Snky
Copy link
Author

Snky commented Aug 20, 2023

Actually maybe there isn't a bug with your isTrigger and I'll continue to try it, I just got back into BitFlag for mask/group and I'll see over time the behaviour and which way I prefer. I had one more question, you said to weld two objects together for the mass issue, how would you recommend welding two RigidBody's together, what type of joint/jointconfig? What settings?

@Dev-MarkoF
Copy link

Welding means a joint that has no degrees of freedom, so a generic joint with it's base config should do the trick.
The 2 bodies are connected and can not on any axis for any amount of distance, the force pulling them together is effectively infinite, so they act as one body.

@Snky
Copy link
Author

Snky commented Sep 22, 2023

I'll give that a go, I probably asked because I didn't actually have a GenericJoint class, so I'm not sure where I got the copy of Oim0 from but I've downloaded the class now and will try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants