- Home /
How to make a projectile in the finger/mouse position in a 2D endless runner?
Hi, Unity Answers community!
I'm having a hard time implementing a function in my 2D Endless Runner game. To put you in the context, the gameplay of the game will have the main character running from left to right, being fixed on the left side of the screen (meaning that the camera is following it only within the x-Axis). One of the gameplay characteristics is to launch a "ball" (projectile), from the characters arm, onto oncoming enemies (that come from the outside right area of the screen). Now, the thing is, I want to implement the function of launching a sprite (or prefab), from the character's arm position (according from the animation's sprite) onto a point (within the allowed x-Axis area) in the screen where the player touched with a finger on it.
I suppose that I should create an "Empty Game Object" in the area of the arm, and then create and "throw" the ball from there.
What are the best suggestions for this?
Well yes, create and Empty in the hand of the player, then based on the position the finger touches you could spawn a temporal Empty (touchPos). Then what would happen is , the empty in the player hand will use a LookAt function to look at the touchPos then it would spawn the projectile going straight to the touchPos.