admin管理员组

文章数量:1313156

I created a dynamic coin. This coin moves like a normal object, hits the ground and is affected by gravity. When I collect this coin with my player object, I can destroy it, but just before it is destroyed, if the coin has a speed, a force affects the player. (Like getting a punch from where the coin came from). I can't make the coin isTrigger because it needs to interact normally with other objects. I can't make the player kinematic because it needs to interact normally with other objects. When I do "Physics.IgnoreCollision(playerCollider, coinCollider);", I can't collect the coins. OnCollisionEnter doesn't work because I don't want a collision and the coin to physically apply force to the player. OnTriggerEnter doesn't work either because isTrigger is closed. Please, how can I solve it?

OnTriggerEnter&Stay OnCollisionEnter&Stay

I created a dynamic coin. This coin moves like a normal object, hits the ground and is affected by gravity. When I collect this coin with my player object, I can destroy it, but just before it is destroyed, if the coin has a speed, a force affects the player. (Like getting a punch from where the coin came from). I can't make the coin isTrigger because it needs to interact normally with other objects. I can't make the player kinematic because it needs to interact normally with other objects. When I do "Physics.IgnoreCollision(playerCollider, coinCollider);", I can't collect the coins. OnCollisionEnter doesn't work because I don't want a collision and the coin to physically apply force to the player. OnTriggerEnter doesn't work either because isTrigger is closed. Please, how can I solve it?

OnTriggerEnter&Stay OnCollisionEnter&Stay

Share Improve this question edited Jan 31 at 14:42 derHugo 90.9k9 gold badges90 silver badges134 bronze badges asked Jan 30 at 20:59 AbdAbd 11 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 0

I would simply add a child to the player on a different layer - let's call it COINCOLLECTOR with a simple Trigger collider (sphere for instance). Probably doesn't have to be a mesh collider and you can save some performance that way.

Then configure the layers so that only the player child trigger interacts with coins, not the player itself.

This way

  • COINS just keep interacting with basically all you already had
  • PLAYER also keeps interacting with the rest of the world
  • PLAYER does NOT collide with COINS so there will be no physics impact caused by the coins
  • but COINCOLLECTOR can collect the COINS using a trigger

本文标签: Unity 3d collectible coins physically apply force to the playerStack Overflow