Forum begins after the advertisement:

 


[General] Option to make joystick disappear when not pressed

Home Forums Unity Assets Support Virtual Joystick Pack [General] Option to make joystick disappear when not pressed

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #17841
    Jukers
    Level 9
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I have been using the Terrasqual joystick on my Vampire survivors clone, and i came to realise that the joystick used in the tutorials doenst have the option to disappear when not pressed like vampire survivors and many other games, i tried to make something similar (not really good with c# scripting) and i made a system that makes it “disappear” when not used for x amount of time

    basically, when not used for x amount of time the joystick gets teleported of screen, and by using “Snaps to Touch” it gets back on the screen. the problem with this approach is that for example, if i make the joystick teleport off the screen on the left, the next time i click on the screen, the character will move to the right, as the joystick is being called left to right

    i know that this approach have a lot of issues, send your suggestion!

    VirtualJoystick.cs

    //existing code...
    private float lastUsedAt;
    public float idleTime = 0.1f; //amount of time that it takes for the joystick to disappear
    //existing code...
    
    void Update(){
        //existing code...
    
        if (axis.sqrMagnitude > 0)
        {
            lastUsedAt = Time.time;
        }
        if (Time.time - lastUsedAt >= idleTime) {
            gameObject.SetActive(false); //disable the object so that works properly when teleported
            transform.position = new Vector3(-720, 0, 0); // teleports of screen
            gameObject.SetActive(true); //activate it again
        }
    }
    #17848
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    That is a great suggestion Jukers. I like it a lot :)

    Let us work on implementing it. I’ll send you the code we come up with so that you don’t need to wait for us to release the full package as well.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: