2

I am making a First Person Shooter and I have a player model(3D), rigged, with animations and a Skinned Mesh Render component on it. I tried the Mesh Collider component, but it has a large negative impact on the game performance (animations, frames per second). So I thought, there must be a way to make your own Raycast System(Script, Variable), but I don't know where to start. Is there a way to look into the RaycastHit component script of Unity or do you guys have any ideas how to start making an own Raycasting Script, which doesn't need collider, but supports the Skinned Mesh Renderer component?

P.S. I need it for shooting at players.

Je moder
  • 83
  • 1
  • 1
  • 11
  • How are your players going to interact with the rest of the physics world without a collider? And I highly doubt that creating your own system would yield better results either. If anything you could consider using multiple simpler collision shapes (capsules, spheres, boxes) to create a "collision mesh" for performance optimization – UnholySheep Mar 08 '19 at 23:12
  • @UnholySheep I have a Capsule Collider for the interacting with the world and I thought about simpler collision shapes, but this causes bugs (you actually hit the player, but not the collider). I don't know if there is an option to decrease the amount of triangles in a Mesh Collider component, that could be a solution. – Je moder Mar 08 '19 at 23:45
  • Mesh colliders have various cooking options (https://docs.unity3d.com/Manual/class-MeshCollider.html#cooking) that might help. And attaching multiple simpler collision shapes should not cause issues like you described, unless you didn't set them up correctly (and have gaps between them where the player mesh is still visible) – UnholySheep Mar 08 '19 at 23:50
  • I'll take a look at the cooking of Mesh Colliders, but what you say about simpler collision shapes is almost impossible with the amount and different amount of animations I have to play. – Je moder Mar 08 '19 at 23:53
  • There are [assets](https://assetstore.unity.com/packages/tools/physics/rascal-skinned-mesh-collider-134833) [on the](https://assetstore.unity.com/packages/tools/physics/rascal-skinned-mesh-collider-134833) [asset store](https://assetstore.unity.com/packages/tools/integration/dynamic-raycast-system-2-0-20844) that do this. – Draco18s no longer trusts SE Mar 09 '19 at 02:48
  • 1
    @Draco18s That's not for free ;). – Je moder Mar 09 '19 at 09:01
  • @UnholySheep The highest frame-rate I've got is 21 fps with a mesh collider, when I'm playing myself, if I play with more players it's possible to disable my own, but I have to render the Mesh Colliders of all the other players, which will cause 0.3 fps maybe? – Je moder Mar 09 '19 at 14:16
  • @DaniëlvanderZwan You're going to have to decide if the price for a working system exceeds the amount of time you're willing to work on it yourself. Given you have no idea how to even start, that suggests that $10 is a minimum cost worth paying. Eg. I'm paid $45 an hour (roughly speaking), so for every hour I save not programming something myself is worth about $45. I estimate it would take me 3 months to write my own system (and it wouldn't be as good). So anything under about $21,600 is worth it to me. – Draco18s no longer trusts SE Mar 09 '19 at 16:36
  • @Draco18s Stackoverflow is a learning forum isn't it, I want to learn how to do it myself. But for now I have chosen for less accuracy and better game performance by multiple simpler colliders (which is tough too, because of the animations). – Je moder Mar 10 '19 at 17:16
  • @DaniëlvanderZwan Not really. It can *answer concrete questions.* And that can *aid* learning, but Stack Overflow [is not a forum](https://meta.stackoverflow.com/a/294776/1663383). "How do I do X?" [is too broad](https://softwareengineering.meta.stackexchange.com/a/6367/322319). "I am trying to do X, here's what I tried, but Y doesn't work." is answerable. – Draco18s no longer trusts SE Mar 10 '19 at 18:16

1 Answers1

1

Don't use a mesh collider on a mesh that is dynamically controlled by bones (a rigged mesh). This is just too heavy for most computers. I recommend to use multiple capsule colliders for the limbs and head, and use 1 or 2 box colliders for the chest/stomach. Attach these colliders to the bones so the colliders will move along with the animations. In this way you can use the default raycast system of unity: Physics.Raycast.

cigien
  • 57,834
  • 11
  • 73
  • 112
Je moder
  • 83
  • 1
  • 1
  • 11