I need helppp!!

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!

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.

1 Like

you need to find problems before asking for help

**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.

Thx for all the feedback.

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

I got everything except for the boomerang effect done… do you know how on earth I can implement a boomerang effect

@spikeybubblez

One way to do movement towards a target:

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.