Search Unity

2D Hitbox connection

Discussion in '2D' started by colego328, Apr 24, 2017.

  1. colego328

    colego328

    Joined:
    Apr 10, 2017
    Posts:
    21
    Hello Unity! I wanted to make a my character latch onto the ridgedbody or hitbox of enemy, and then let go after a certain amount of time. How would I program that?
     
  2. donbaloo

    donbaloo

    Joined:
    Apr 24, 2017
    Posts:
    3
    I'm very new to scripting and have only been studying C# basics so take my solution with a grain of salt. I'm 100% certain there are better ways and hopefully someone will come along and offer one of those. Until then, here's what I'd do with my basic knowledge.

    At OnTriggerEnter2D, I'd find the X,Y position difference between the character and the enemy and then set the character's position at that difference until released. I'd start a simple timer by accumulating Time.deltaTime and once I reached my desired latch on duration I'd return to my standard character position code.

    Remember, this could be a terrible solution!