Jump to content
  • Advertisement
Sign in to follow this  
Cuber01

Unity How do I get a bullet trail to follow a mobile joystick in unity

This topic is 662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a 2D Platformer in unity using c#. I am working on adding mobile controls to the game. Right now I have one joystick that controls the player movement as well as rotating the arm to shoot the enemies that come from above

Issues I am running into

When I move the joystick to move the player the arm does rotate but the bullet trail that kills the enemies does not follow as well.

What I have done

I did import the CrossPlatformInput libary to the script. I tried to change the Input.mousePosition to CrossPlatformInputManger but all it did was stay in one place.

Here is the weapon script with the shoot method

void Shoot ()
{
Vector2 mousePosition = new Vector2 (Camera.main.ScreenToWorldPoint (Input.mousePosition).x, Camera.main.ScreenToWorldPoint (Input.mousePosition).y);
Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
RaycastHit2D hit = Physics2D.Raycast (firePointPosition, mousePosition-firePointPosition, 100, whatToHit);

Debug.DrawLine(firePointPosition, (mousePosition – firePointPosition)*100, Color.cyan);
if (hit.collider != null)
{
Debug.DrawLine(firePointPosition, hit.point, Color.red);
Enemy enemy = hit.collider.GetComponent<Enemy>();
if (enemy != null)
{
enemy.DamageEnemy(Damage);
}
}

Share this post


Link to post
Share on other sites
Advertisement

This topic is 662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!