Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How do I get collisions & velocity without object stopping

Discussion in 'Physics' started by simon_unity326, Mar 2, 2024.

  1. simon_unity326

    simon_unity326

    Joined:
    Feb 25, 2024
    Posts:
    2
    I am trying to make a bullet system for a multiplayer-superhot-thing I'm making, and I'm making the bullets start off inside of the player. I am trying my best to only 'borrow' code that I understand (so far the only thing that has stopped me quaternions or smth like that). With how I'm doing it, the bullets start inside of the player, this wouldn't be a problem if it didn't clip to outside of the player and modify its velocity. Could someone help me with this please?
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,495
    Colliders with their "isTrigger" flag set to false will be considered solid, and if they also have a Rigidbody then that Rigidbody will apply force to move the object so it's not overlapping with other solid objects.

    You can make your bullet collider a trigger, or you can remove its Rigidbody, or you can set its Rigidbody to "isKinematic" so it doesn't move with forces.

    Many bullets use a trigger collider instead of a solid collider, for reasons like this. Then you use OnTriggerEnter instead of OnCollisionEnter, to process the possible hit of an enemy collider.
     
  3. simon_unity326

    simon_unity326

    Joined:
    Feb 25, 2024
    Posts:
    2
    So how do I make it move? aside from with code every single frame, the rigidbody is what allows velocity, right?
     
  4. dstears

    dstears

    Joined:
    Sep 6, 2021
    Posts:
    152
    You can still have a rigidBody on an object with a Trigger collider. The bullet collider and the player collider can overlap but the physics engine won't try to force the colliders to separate if the bullet is set to Trigger.

    Another option is to use a different physics layer for the bullet and Player and turn off the interaction between the Player's layer and bullet's layer. There is a grid under Edit -> Project Settings -> Physics which dictates which physics layers interact.