Hello, first post and total novice, apologies if this question is a tad noob. I did search beforehand but im afraid I may not recognize the answer if I saw it, lol, Anywho, my goal at the moment is to get a 2D sprite to move around the screen using the WASD keys and tack on features as I can figure them out. Right now Im working on collisions and I simply can not get him to be stopped by another sprite.
I am using 2D Toolkit although I don’t thin that factors into this (it may). I have assigned Mesh Colliders to my dude and a block sprite. I used 2Dcollidergen to generate the collider mesh but in all other ways im sure its just a plain ol’ Mesh Collider. I have tried with and without rigid bodies, either convex, both convex, neither convex. I DID read this “If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.” And if I understand what I’ve done correctly I am moving the object via transform.
The rigidbody didnt seem to help anyways. But even so, I don’t need physics (at least not yet). I simply want him to move, and stop when he hits a solid object. Any advice is appreciated!
transform.Translate is not affected by physics and will always move exactly where you tell it to regardless of colliders and physics. You must move the object using rigidbody forces instead.
Also, from Unity’s mesh collider page:
Mesh Colliders cannot collide with each other unless they are marked as Convex. Therefore, they are most useful for background objects like environment geometry.
Convex Mesh Colliders must be fewer than 255 triangles.
You shouldn’t use mesh colliders for anything moving; use primitive colliders instead. If you really can’t get a good collision shape with a primitive collider or compound primitive collider, you can use a convex mesh collider as a last resort.
Dasbin, thanks for the info, I had a terrible feeling that I wasnt going to be able to use the transform.Translate to move him lol. I was simply to thrilled to see it actually worked to change it
Eric5h5, I was under the impression that Rigidbody would only be required if I wished to take advantage of physics, but it appears its a pretty common component. You say I should use convex mesh collider’s as a last resort. If you have a spare minute, could you tell me why? Uses more resources maybe?
Yes. However if you have collisions set up properly (see the table at the bottom of this page for what collides with what), transform.Translate will in fact work for colliding, though you can translate “through” an object if you move it too fast.