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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Create Character controller similar to Doodle Army 2 - Mini Militia.

Discussion in 'Getting Started' started by Aymanfaruk15, May 4, 2021.

  1. Aymanfaruk15

    Aymanfaruk15

    Joined:
    Apr 30, 2021
    Posts:
    3
    I'm relatively new to Unity and I've been practicing with very simple 2d projects(like Tetris, etc), now i wanted to step up my game and create a game like Mini Militia for fun. Here are what i have:

    - I have a character controller with an empty script(for movement, etc) and also a 2d collider and a rigidbody2d.

    - I also have two custom joysticks(similar to DA2 - MM) which i made following a tutorial:


    And here's what i would like to do:

    - Use the left side joystick for moving(while on ground) and fly while off the ground.
    AND use the right side joystick for aiming(while the joystick is within certain range) and shooting if the joystick is out of range.


    Very similar mechanic to Doodle Army 2.
    Here's an image for reference:
    1pu0of52vmc51.jpg

    Thank you very much in advance.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,498
    Welcome to the forums! I didn't see a question in your post, so I'm assuming you want someone to just create the character controller for you? That's not really how things work here.

    Could one of the forum members create this controller and share the code with you, which would then just work? Yeah, sure. But what would you learn from that? How would you then be better equipped to handle the next task in your project? You're much better off figuring out how to do these things by learning the fundamentals, practicing, experimenting, and applying what you've learned rather than just requesting or receiving big chunks of code that you don't understand.

    Keep following tutorials, even if they don't seem to be directly related to what kind of game you're trying to make. Each bit of experience will help you understand how the engine and API work as a whole. When you feel you have enough of an understanding to take on your project, begin in earnest. And when you run into problems in that project, use Google or the forums to ask specific and focused questions, and we'll happily steer you in the right direction.

    There's no shortcut to experience.

    Good luck!
     
    Aymanfaruk15 likes this.
  3. Aymanfaruk15

    Aymanfaruk15

    Joined:
    Apr 30, 2021
    Posts:
    3
    Hello @Schneider21 thanks for the advice, and I'm really sorry for the late reply.

    I get your point: don't depend on others but learn it yourself, and i totally agree with you. I wasn't asking someone to write the code for me or something(I'm a decent programmer myself) since that would defeat my purpose of learning Unity, i was looking for someone to point me to the right direction like: concept or resource.
    I don't know if Unity Forum isn't the right place to post this kinda topic but i posted this same post on Unity Answers and I haven't received an answer yet and I've also been on YouTube and Google and i haven't seen relevant stuff. I've been at this for almost 2 months.

    I should've clarified my post but here's my current status:
    • Left Joystick(Movement) is kinda working i take in Vector2 from the joystick, multiply it by speed and then apply it to the character's velocity.
    • My main issue is the Right Joystick which is for aiming and/or flipping the character, i can't really seem to figure it out, I can go into details if you'd like to help with this.

    Thanks again for your reply.
     
  4. PrabhakarDeep

    PrabhakarDeep

    Joined:
    Jun 6, 2019
    Posts:
    6

    Just trying to implement same kind of controls to my game. Just figured out how simple it is to do.

    I'm using new Input System for my game.

    In your right stick script:

    1. Get the value of rightStick position.
    2. Check the absolute value of rightStick after which you want to call Shoot().

    My code snippet.

    if(Mathf.Abs(gamepadPos.x) > 0.8 || Mathf.Abs(gamepadPos.y) > 0.8)
    {
    isFiring = true;
    Shoot();
    Debug.Log("Fire");
    }
    else
    {
    isFiring = false;
    Debug.Log("Stop Fire");
    }


    You can experiment with the Right Stick deadzone.
    I hope it may help you.
     
    Aymanfaruk15 and Schneider21 like this.
  5. Aymanfaruk15

    Aymanfaruk15

    Joined:
    Apr 30, 2021
    Posts:
    3
    Thanks @PrabhakarDeep , it works like a charm even though i was using custom joystick input.
    I set the deadzone to 0.6f.

    The only thing I'm left with is aiming and rotating the character to face the direction the joystick was moved to. I'm not sure how to aim but i tried changing the local(transform) scale but it also changes the character's position.

    Here's my character's hierarchy:
    plays.PNG

    And this is the issue I'm facing:
    20210601_224446.jpg


    20210601_224423.jpg
     
  6. PrabhakarDeep

    PrabhakarDeep

    Joined:
    Jun 6, 2019
    Posts:
    6

    Add a script to the Head GameObject.

    In the update() calculate the scaler product of vector3 lookDirection and gamepadPos value here is code snippet.

    Vector3 lookDirection = Vector3.right * gamepadPos.x + Vector3.forward * gamepadPos.y;
    if (lookDirection.sqrMagnitude > 0.0f)
    {
    transform.rotation = Quaternion.LookRotation(lookDirection, Vector3.up);
    }

    This is code of my top-down shooter game.
     
  7. minimile

    minimile

    Joined:
    Oct 28, 2021
    Posts:
    1
    This is only possible in mini militia hack version which you can download from here https://mini-militia.com you can also download it's official version because in a official version you can't do this.
     
    robertrocks2342 likes this.
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Website? This is C# code that would go into a Unity script file. If you meant your WebGL build, please share the code you already have and describe the problem that you are having.
     
unityunity