Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

I need helppp!!

Discussion in '2D' started by spikeybubblez, Apr 2, 2021.

  1. spikeybubblez

    spikeybubblez

    Joined:
    Apr 2, 2021
    Posts:
    4
    basically I'm making a 2-d platformer with a ninja star weapon. What I want it to do is launch in the direction the players facing, keep moving until a certain period of time runs out or it hits a platform, then boomerang back to the player. I started using C# less than a week ago and I have no idea on what I'm doing. Help would be so GREATLY appreciated! thank you in advance!
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi!

    "I started using C# less than a week ago and I have no idea on what I'm doing."


    So what have you tried/done so far?

    You already have the steps, so make your idea look more like pseudocode:
    - Player presses a button
    - Launch a projectile in the direction the player is facing
    - Move until A. timer runs out / B. projectile collides with a platform
    - Move back towards the player

    Start solving each step one at a time. Start from the first task and after you are done, solve the next one. Use search engine a lot. If you get stuck and can't figure it out, ask a question here.

    And you probably want to check collision with your targets too. When your projectile hits its target, you'll have to figure out some way to reduce the health of your target.

    BTW - this question could equally well be asked in general scripting forum, there is nothing 2D specific in your question IMHO. Also, 'I need helppp!' isn't very informative either.
     
    spikeybubblez likes this.
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you need to find problems before asking for help
     
  4. SancleMente

    SancleMente

    Joined:
    Apr 3, 2021
    Posts:
    2
    For the direction:You can use Quaternion.Euler to read the direction your player is facing. If the player is looking to the right the the speed will be positive, if its looking to the left then the speed will be negative. The speed would be based on the X-axis.
    For the timer: you can use two IEnumerator coroutines one for shooting and one for the boomerang effect. The shooting coroutine. When pressed a key the shooting coroutine starts and after the timer ends you start the boomerang effect.
    To shoot: you can use Input.GetKeyDown(Keycode.x) and a bool variable to check if u shot already.
    For boomerang effect: first add a boxCollider2D to the ninja star then you could use a void onCollisionEnter2D (inside the star GameObject)that stops the shooting coroutine and starts the boomerang effect.
    Then combine all of that into a script. I would suggest learning a bit more about the language before trying to make a game.
     
    Last edited: Apr 3, 2021
  5. spikeybubblez

    spikeybubblez

    Joined:
    Apr 2, 2021
    Posts:
    4
    Thx for all the feedback.
     
  6. spikeybubblez

    spikeybubblez

    Joined:
    Apr 2, 2021
    Posts:
    4





    thx! I don't know to much about c# but I figured that coding this game would help me understand it!
     
  7. spikeybubblez

    spikeybubblez

    Joined:
    Apr 2, 2021
    Posts:
    4
    I got everything except for the boomerang effect done... do you know how on earth I can implement a boomerang effect
     
  8. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  9. SancleMente

    SancleMente

    Joined:
    Apr 3, 2021
    Posts:
    2
    You can add a boxCollider2D to the ninja star, then add a script to said object also. Then you can name the player script inside it so after a certain amount of seconds it will do the boomerang effect. That would be for the time, for collision boomerang effect u can create a private void onCollisionEnter2D and add the boomerang effect. Now when it shoots and it collides into anything it will go back, and if it doesnt it will go back after a certain amount of seconds.