What would be the best way to adjust the height of a rididbody when for example my character goes into crouch position? would it be to get a reference to the rigid body and manually change the height etc, or would a mesh collider be a better option? Im open to any suggestions, I'm just curious what would be the best way to go about doing this.
Rigidbody itself doesn't trigger collisions, only colliders does so you should change the height of collider.
In my opinion cylinder collider is a better option then mesh collider because it produces less overhead, is easy to scale (for example by just changing height) and is quite good approximation of humanoid mesh.
So just keep a reference to cylinder collider attached to game object and changed height of collider whenever your character goes into crunch position.
Related
I'm trying to create a platform game, watching videos and tutorials I see that they use the Tile Palette option very frequently.
When creating the 2D Tilemap Collider, each square has its collider, and I guess that makes it consume a lot of resources, so to solve that I create a 2D Composite collider.
The problem is when the player collides with the collider of a vertical wall, causing the player's rigidBody.velocity.y to add force and that doesn't allow me to execute the jump.
https://clipchamp.com/watch/nFKCJOv7DEX
Here you can see under the scene of the game the debug.log that ends up showing me a speed to the Y axis
This project would be for android, and I would like to optimize it as much as possible. Do you have any idea so that in that collision I do not add force Y?
I have tried to change the speed in an onColliderStay2d and put the vertical tilemaps with another tag to differentiate them from the ground, but nothing.
Instead of checking your y velocity to see if you are grounded or not I recommend just making a rectangular area under your player character and check if it overlaps with the ground using Physics2D.OverlapArea. It's way less error prone.
Also, just because composite collider creates less shapes than tilemap collider doesn't mean it is less performant, the physics system doesn't iterate them one by one. Do yourself a favor and just use the tilemap collider instead.
I have a lot of problems with some 2D colliders.
In the past, they work, but now they are horrible:))
I already try with Kinematics, OnCollision2DEnter, OnTriggerEnter etc.
The objects are already on the same layer, the same position on the Z-axis, they interact with each other but my game can't detect the collisions.
The rigidbody and collider don't have material but the objects have skins enter image description hereenter image description here
I've realized that the gravity scale of your ground object is above 1. You can make it 0 so it does not get affected by gravity. Gravity Scale is on your ground object's Rigidbody2D component right below angular drag. Although I could be wrong since what kind of collisions you are expecting and your movement code, that should help resolve your problems.
I have a sphere collider on a stick and a cylinder. The cylinder has to detect a collision with the sphere collider of the stick and fire up a "OnTriggerEnter" script. Just imagine it like a drum stick hitting a drum in virtual reality.
Is there a way to avoid registering a collision on the sides of the cylinder, but only trigger on the top of the cylinder? And even without adding more protecting objects around it?
In the screenshot you see the properties of the stick and below the properties of the cylinder.
Obviously the green and red icons show which area is allowed to be triggered and which not.
Btw, simply using a thinner cylinder collider doesn't work in this case, because it wouldn't detect some collisions at all, when the stick goes too fast trough the thin cylinder. More about that in the comments.
Thank you.
Can we detect mesh collision in unity3d? I want to show some texture on collision, currently I am using box colliders, that's why its surface/edge do not match with the object body mesh, Also even if I get the hit point on the surface of mesh, I don't know how to put a texture on a mesh at specific position over mesh, is there any in-built component specific for the same kind of requirement or a workaround of this in unity3d?
As we can see in picture the collision has been detected inside the game object because the box collider is inside the target object mesh
Note: here the actual mesh I have replaced with a dummy cube mesh
But is there any way to detect when bullet collider/mesh was actually going through the mesh of the target object as in below image I have shown where exactly I want to detect the hit point between target object mesh and bullet mesh/collider also how to draw a texture over here (the hit point on the mesh).
Short answer: No
Because that's not how that works.
Long answer:
If you want the mesh to be used as the collider, you should set the mesh as the target for a MeshCollider component. However, mesh colliders are very expensive: Unity needs to recalculate them every time they move, scale, rotate, or otherwise change their boundaries.
There is, however this asset which will perform raycasts against the renderer mesh, without the need for a collider, but I have no idea what kind of performance hit that will have.
This is the setup I have. I am trying to make a game in unity which appears 2d but is actually 3d. I have a simple sphere and a floor, which is made up of cubes placed next to each other(the colliders overlap a little) with the same Y value and Z value. My 2d plane is in X-Y plane(Z being the depth).
Now in the script attached to the sphere, in the Update function, I have used rigidbody.addForce() in the +ve X axis function to move the sphere forward. I have attached rigidbody to the sphere and enabled gravity. The collider of the sphere is the default one.
Now the problem is:
When I run this scene. The sphere moves forward but at the intersection of the colliders, it jumps a bit(very less but still noticable) upward and loses its momentum. It happens at every intersection.
BUT this does NOT happen if I place the sphere on a floor made up of a SINGLE cube(a very long one).
Is this problem arising because of overlapping colliders? How do I solve this issue?
Thanks in advance
I don't think this is fixable. Unity physics is approximate, and even when physics material are set up to 1.0 bounciness, momentum doesn't stay constant — I learned it the hard way when I tried to develop a game depending on constant momentum, and had to write my own little physics simulation for that.