Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Discussion Seeking advice on implementing stabbing mechanics in my Unity game, inspired by Boneworks

Discussion in 'VR' started by teatime_penguin, May 2, 2023.

  1. teatime_penguin

    teatime_penguin

    Joined:
    May 3, 2022
    Posts:
    25
    Hello everyone,

    I'm currently working on a project that is heavily inspired by the physics-based sandbox game "Boneworks". I'm trying to add stabbing mechanics to my game, but I'm struggling to figure out how to implement this feature and i don't want to pay money for a unity asset.

    I would really appreciate it if anyone could provide me with some code snippets or suggestions on how to go about adding stabbing mechanics to my game. I have some experience with Unity and C#, but I'm not very familiar with implementing physics-based gameplay mechanics.

    My goal is to allow the player to stab objects with a knife or other sharp object. The stabbing should be realistic and dynamic, so the player can stab at different angles and locations on an object, and the object should react appropriately to the stab and the stabber should be able to move in the body.

    If anyone has any suggestions or code snippets to share, I would be extremely grateful. Thank you in advance for any help you can provide!
     
  2. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    188
    Allow the knife to be parented to a stabbed object / person upon release, and make sure it keeps it's local position relative to the stabbed object at that point. Unparent the knife if it's pulled back out. You'll want separate colliders for the handle and blade so you can turn off the blade's colliders while it's entering/exiting. Only make the handle half an interactable. Add whatever VFX you want for blood. Probably would work a lot better for a knife than a katana, I think a long blade would make thing 5x harder unless you liked the no-clip like effect for it. Start with XR Toolkit, or buy something with a lot more alternatives for more advanced physics interactions if that's the rabbit hole you want to go down. Physics interactions in VR are generally a very complicated and advanced topic. There is a reason Boneworks took so long to get right.
     
  3. teatime_penguin

    teatime_penguin

    Joined:
    May 3, 2022
    Posts:
    25
    alright thx i see what you mean