Wheel Collider has different rotation with the wheel GameObject - unity3d

I want to add a wheel collider in my car wheel but it comes with 90-degree rotation.
This is the image:
How can I adjust the collider to the car wheel?

For further reference, i am writing down my comment as answer.
Simplest solution that i can think of is; add an empty gameObject. Attach wheel collider to that empty gameObject. And make the empty gameObject child to your car's wheel. With this you can rotate the empty gameObject so that your collider will be rotate. #Programmer also shared a link about WheelCollider Tutorial. Which can be found here

One of the best thing you could do is that, before importing the game object, make sure that the game object is Y Forward. You can change that in blender while exporting.

I had the same problem. However, simply rotating an empty parent object doesn't work in the modern version of Unity (2019.4). You have to rotate an object that has the rigidbody that the WheelColliders are attached to.
Assuming that your car has a rigidbody, the solution is to make sure that the X-axis orientation of the car's rigidbody matches the desired X-axis orientation of the wheel colliders.
Based on this post:
https://forum.unity.com/threads/unity-5-wheelcollider-wrong-rotation.349596/#post-2264801
WheelColliders always point in the "forward" and "down" direction as the rigidbody they're attached to. The steerAngle value is relative to the rigidbody's forward direction.
Please bear in mind, however, that your car's model(the visuals that display the car body) might have a different orientation from the object that contains the rigidbody that wheel colliders are attached to.
In my case Hierarchy looked like so:
MainScene
CarRoot
CarModel
WheelColliders
Wheel_FR
Wheel_FL
Wheel_RR
Wheel_RL
The CarRoot had a rigid body on it. When I rotated it, it would rotate the wheel colliders with it. That would also rotate the car model. Which was not good. So I had to:
Unparent the CarModel and WheelColliders(made them children of MainScene)
Rotate the CarRoot by 90 degrees on the Y-axis(to align its X-axis with that of the WheelColliders)
Make CarModel and WheelColliders children of CarRoot again.
That did it for me.
P.S. Sorry if this is a bit of a necro-bump. But this still has no answer.

I had a ton of trouble over this because none of the export settings or rotations in Blender fixed the problem for me. I eventually found a solution though. Create an empty gameObject, and attach the rigidbody, mesh filter, and mesh collider to it. Then parent the model to the empty gameObject, and then try adding wheel colliders. Wheels are relative to the rigidbody's transform.up and transform.forward, so putting the rigidbody on a default thing fixes all the issues.

Related

How to add an gameobject to an animated rig properly

I have moddeled and rigged an human in blender and I am able to play that animation in unity.
Now I am trying to add some objects to the human. For example an hat. But I cannot figure out, how it is made that the hat moves withe the animation.
I know, that the head has got the animation data. The hat does those data not have, hence the hat does not move.
How do I do this? Another scenario would be grapping sth. with the hand and that object should move together with the hand movement.
I would like to add those objects via script later on.
Thank you very much :)
In your character's rig in the unity scene,
Find the Bone that you want your target GameObject to follow, and add the target GameObject as a child of the bone GameObject in the Scene heirarchy, and position it with whatever position and rotation offset you need (In this case, on the head bone, maybe a little tipped)
In this case, you would find the Head bone of your rig, and add the Hat as a child gameobject of the head bone. Any animation you play, which modifies the bone positions should also move your target GameObject.

Capsule Collider not visible in the scene view?

I am trying to hit a ball using a golf club. My golf club has three components (three game objects: handle, shaft and head as shown in the first attached image). Head gameobject's inspector can be seen in the another attached image.
To hit the golf ball, we need a collider. So I put a Capsule Collider at head game object. But I don't see any collider at head gameobject.
The head is shown in the last image.
Why I can't put Capsule Collider at the object?
EDIT:
Thanks for the reply.
I increased the radius but still the same.
I placed a Quad in the scene and put Mesh collider onto it (called AW52Collider). Please see in the
first image. We can see the collider clearly.
But I did the same thing to Club head, as it is also a game object I should be able to put a Mesh collider. But I don't see anything. Why?
Please see in the second image.
One more thing I don't understand is when I put AW52Collider inside Club Head object, I don't see AW52Collider also. Why? Please see in the third image.
Increase the size of your collider, those values do not look like you should see the gizmos at all. Best would be to reset the collider to its default values and then play with them until you are happy.
It is best practice to create a child object with colliders on it. The reason is the placement of the collider. The collider is always centered around the pivot point of a GameObject. But you probably want to move your collider freely or disable a group of colliders manually for testing (or optimization) purposes. Also consider that an object with multiple small colliders as child objects is considered one big collider (rigidbody wise). Source (Compound Colliders)
Just enable Gizmos button and you'll find your capsule collider.
See this picture to know exactly where to find it:
(It's in the toolbar below the Scene tab)

Why the player is walking through objects in scene?

Instead walking on the ground he walk through it same for the ship and debris the other objects. He stay on the ground on the terrain but all the other objects in the scene he walk through it.
In the past i added Mesh Collider to the ship sapceship and checked the Convex turned the Convex on so it worked fine. but now i tried to add Mesh Collider almost to everything in the scene and it didn't change anything.
The scene is not my own but there is nothing speical i think. A terrain camera and objects. I added the ThirdPersonController.
Maybe there is a way to solve it making a new script in c# ? So far i could not find solution.
Make sure the collider of the Player is big enought to hold the model. And also that the terrain collider is adjusted to the terrain.
Try to change Center(Y) value of CapsulCollider

Primitive colliders on complex model in Unity

I just imported my tree model from blender and i want to add colliders to it. It has animation attached to it(tree is breaking and falling). I have read about adding colliders to animated objectsand from what I understood I just have to add many primitive colliders to different bones. My problem is that I can't rotate this primitive colliders and i cant make them fit shape of the object. Is there any better way to do this?
You could create an empty gameobject under the bone and add the collider onto that. The colliders rotation follows the rotation of the gameobject it was added to.

Rigidbody between two terrains getting dragged to the upper one

If a rigidbody is below a terrain it is getting dragged up on the terrain
I have 2 terrains, one over another to make a cave like shape. If I put a rigidbody on terrain below it is getting dragged onto the terrain above. So i cant even put a single rigidbody inside that cave.
I tried with mesh collider on terrain obove instead of using terrain collider. But terrain does not have an actual mesh, so it didnt work.
Is there a solution to overcome this?
Since Unity's TerrainCollider is height-map based, you can't put one on top of the other and expect proper collision detection.