Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Cycling Player Lock-On Targets Using Thumbstick

Discussion in '2D' started by LiberLogic969, Mar 16, 2017.

  1. LiberLogic969

    LiberLogic969

    Joined:
    Jun 29, 2014
    Posts:
    138
    Hello,

    I'm trying to create a lock on system that allows me to cycle through potential targets.

    Right now I have targeting and locking-on working fine. I click the right thumbstick button to find the closest enemy within my lock-on range and set them as the target.

    How I would like it to function is by taking the horizontal direction of the right thumbstick and searching "within" that direction for a new target that is the closest to the current target. Think about it as a top-down 2D version of Dark Souls/Bloodbornes/Niohs targeting system.

    I can't think of an elegant way to achieve this. I've tried a few things but they've given very unpredictable results.

    Any ideas?
     
  2. ShaseOfBase

    ShaseOfBase

    Joined:
    Nov 13, 2016
    Posts:
    5
    How about firing a bunch of raycasts from the currently targeted object in the direction of the thumbstick? Apply target to first targetable object hit.
     
  3. LiberLogic969

    LiberLogic969

    Joined:
    Jun 29, 2014
    Posts:
    138
    Tried doing that and it was very clunky and inaccurate. I cast several rays out evenly spaced within an angle towards the input direction from the current targets position.

    I was hoping to make it so the target cycling doesn't require actual aiming since for some reason it feels terrible gameplay wise.