Search Unity

Get arrow to enter character and remain stuck there.

Discussion in 'Physics' started by GeorgeMincila, Jan 16, 2019.

  1. GeorgeMincila

    GeorgeMincila

    Joined:
    Feb 28, 2016
    Posts:
    36
    Hi,

    My project is for mobile phones. I have two game character in 3D space, enemy and hero. Hero is controlled by the user with an onscreen joystick.

    Hero and enemy shoot arrows at each other. Arrow gets instantiated and gets a velocity. For that it needs a rigidbody.

    Hero has a rigidbody so I can move him in the direction the user is moving the joystick, while showing the animation of the legs moving.
    Hero also has a capsule collider, so I can detect when it has been hit by the arrow.

    The issue is, both arrow and hero being rigidbodies, when they meet, they apply forces to each other, so I made the collider on the hero to have isTrigger checked to prevent that.
    So currently the arrow passes through the character while I record the damage.

    I would like for the arrow to get in the hero with its tip and get stuck there for 0.5s before fading out.

    Appreciate any lead as to how and what components each should have to get this working.

    Thank you.
     
    Last edited: Jan 16, 2019
  2. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I think you maybe able to just make one a trigger.

    Or add code for the oncollision enter function and you should be able to stop the collision response.
    Disable the rigid body etc. there should be a callback to let you do this.

    If for some reason you can't you can put a second collider that is a trigger on your hero that you add code that handles the on triggers before the arrows actually impact your main rigid body collider and you can adjust things then.
    The trigger collider would be a little bigger than the other one so it's triggered first.

    Or play with the masses. So the reaction is minimal.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    OnCollider/TriggerEnter -> Disable the arrow rigidbody/make it kinematic and parent it to the object it hit.

    I think you can keep it as a normal collider like that.

    Also, let the graphic on the arrow extend beyond the collider where the head of the arrow is so it looks like its in there good and not stuck in the first layer of atoms(as a real-world counter part, unless you have a really advanced voxel engine, hehe)
     
    daxiongmao likes this.