Search Unity

Trying to recreate 2D and 3D Metroid mechanics

Discussion in 'General Discussion' started by DordusRising, Mar 17, 2023.

Thread Status:
Not open for further replies.
  1. DordusRising

    DordusRising

    Joined:
    Dec 13, 2022
    Posts:
    37
    I'm relatively new to Unity. I recently learned how to code double jump in Unity, but I want to take things a step further. I want to learn how to create/translate mechanics from the 2D and 3D Metroid games into Unity. I plan on working more on 3D games. Here is a to-do list of mechanics I want:
    Arm Cannon w/Charge Beam
    Space Jump w/Screw Attack
    Speed Booster w/Shinespark
    I'm going to ask around and see if anyone knows how to code these in Unity and translate them into 3D.
     
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    This belongs in the Scripting forum.
     
  3. DordusRising

    DordusRising

    Joined:
    Dec 13, 2022
    Posts:
    37
    I thought it belonged there, but I wasn't sure. Thank you!
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    All those mechanics are very basic, if you want to hire people to implement them, see commercial forums. If you want help implementing those yourself, say what your problem is.
     
  5. vintage-retro-indie_78

    vintage-retro-indie_78

    Joined:
    Mar 4, 2023
    Posts:
    285
    not sure, to make a ' charge ' attack, there are quite a few, think you need to have a way to see if a button is pressed, and also code a simple timer, and depending on the timer, the more damage, or other stuff, overall the things you want to do are simple, however it can take months to figure the math, or other stuff, tutorials are an amazing place to start . . .

    overall, there's something called hit - boxes in fighting titles, that indicate where, or then how an attack ' hits ', think it might also help you to look at that genre, perhaps for 2D content . . .
     
  6. DordusRising

    DordusRising

    Joined:
    Dec 13, 2022
    Posts:
    37
    The one that I would like to start with is the Space Jump (infinite jump with jump delay).
     
  7. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,145
    Seeing how simple these task sound you could just have them written by ChatGPT. You can sign up for a free account at the following URL.

    https://chat.openai.com/

    Here are the results after a short discussion (it initially assumed I wanted a double jump and I had to correct it that it was infinite with a cooldown) on the Space Jump mechanic with the bot.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class SpaceJump : MonoBehaviour
    4. {
    5.     [SerializeField] private float jumpForce = 10f;
    6.     [SerializeField] private float jumpCooldown = 1f;
    7.     [SerializeField] private AudioClip jumpSound;
    8.  
    9.     private float nextJumpTime;
    10.     private AudioSource audioSource;
    11.  
    12.     private void Start()
    13.     {
    14.         audioSource = GetComponent<AudioSource>();
    15.     }
    16.  
    17.     private void Update()
    18.     {
    19.         if (Time.time >= nextJumpTime && Input.GetButtonDown("Jump"))
    20.         {
    21.             Jump();
    22.         }
    23.     }
    24.  
    25.     private void Jump()
    26.     {
    27.         GetComponent<Rigidbody>().velocity = new Vector3(GetComponent<Rigidbody>().velocity.x, jumpForce, GetComponent<Rigidbody>().velocity.z);
    28.         nextJumpTime = Time.time + jumpCooldown;
    29.         if (audioSource && jumpSound)
    30.         {
    31.             audioSource.PlayOneShot(jumpSound);
    32.         }
    33.     }
    34. }
    Here's how this implementation works:

    1. The jumpForce variable controls how high the player jumps.
    2. The jumpCooldown variable controls the amount of time the player must wait between jumps.
    3. The nextJumpTime variable keeps track of when the player can next jump.
    4. The audioSource and jumpSound variables are used to play a sound effect when the player jumps.
    5. In the Update method, the script checks whether the player has pressed the jump button and whether enough time has passed since the last jump. If both conditions are true, the script calls the Jump method.
    6. The Jump method sets the player's velocity to the appropriate jump force, sets the nextJumpTime to enforce the jump cooldown, and plays a sound effect if an audio source and jump sound have been assigned.
    Attach this script to your player character game object and test it out. You should be able to perform infinite jumps with a cooldown between jumps. You can tweak the jumpForce and jumpCooldown variables to adjust the feel of the jumps to your liking.
     
    DordusRising and neginfinity like this.
  8. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    I second @Ryiah' suggestion to use ChatGPT. Those are fairly easy to implement, and generally will not be very interesting to explain. The robot is tireless, patient and will be willing to walk a beginner through. Just keep in mind that it can lose track of conversation past 5 or 6 responses.

    That's, of course, unless your country/region is locked out of ChatGPT.
     
    DungDajHjep likes this.
  9. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Wrong forum, off topic. Closed.
     
Thread Status:
Not open for further replies.