I made a simple script for a car I have wheel colliders and they work fine, but when I try to define the center of mass the car stands up when I press start
With center of mass defined:
Without center of mass defined:
I made a simple script for a car I have wheel colliders and they work fine, but when I try to define the center of mass the car stands up when I press start
The center of mass being configured way behind the car’s rear axle. I can guarantee you that Rigidbody.centerOfMass works perfectly. The problem is in your side, verify your scene for:
i have the exact same problem
i know this thread is 2 years old. did you already find a solution to your problem?
If i set my Center of Mass somewhere close to 0, 0, 0, my car will flip back like in your pictures.
when i set the Center of Mass far in front, in the middle of the street, far ahead of my car, like 0, 0, 8, it will show the center of mass of the rigidbody as 0 and everything will work fine.
something adds hell of a mass to the backside of my car and i dont know what. its just made out of 4 wheels and a camera right in the middle of it. there is nothing at the back that could add mass to 0,0,-8 for it to flip back
Regarding the OP, shouldn’t it be:
playerRb.centerOfMass = playerRb.transform.InverseTransformPoint(centerOfMass.position);
?
Or, as a shortcut, if the centerOfMass GameObject is a child of the playerRb, just:
playerRb.centerOfMass = centerOfMass.localPosition;
I think the original problem was centerOfMass.transform.position is in world space, but playerRb.centerOfMass is in local space.
Thanks! that helped.
playerRb.centerOfMass = centerOfMass.transform.localPosition;
the centerOfMass Gameobject was a child of the car, but we (OP and I) both used the global position,
Thats actually what the official Unity Tutorial does aswell. They used the global position in their tutorial video (which is from 2024, so pretty new, but they use Unity2018 in the video.)
here the link to the video in question, in case other people have the same problem: https://learn.unity.com/tutorial/lesson-6-2-research-and-troubleshooting?uv=2022.3&missionId=5f7648a4edbc2a5578eb67df&pathwayId=5f7e17e1edbc2a5ec21a20af&contentId=5f7649a0edbc2a2315d471f7&projectId=5d092adcedbc2a0e5c02d26f#658f5be1edbc2a255f0a71fb