How do I get a bullet trail to follow a movile joystick?
I have been working on a 2D Platformer and right now I am adding mobile controls and I have been able to setup the players movment and jumping, but the problem I am running into is I have a joystick that makes the players arm rotate to shoot the enemies that come from above. Well I was able to ge the arm to rotate, but I cant get he bullet trail to follow the joystick.
What I have done:
I have imported the crossPlatformInput libary and I tried to change the Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
to
Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y);
But all that did was it stayed in one place and did not follow the mouse or the joystick. If someone could help me in the right direction that would be greatly appreicated.
Here is the whole method wihout my changes
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);
//Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612111303im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scrolling background wall collision problem 0 Answers
Inconsistent Jump Heights 1 Answer
how create EndLess game Like zombie Tsunami 1 Answer
2D Platformer Gun Equip Script Not Working 0 Answers
2D Bullet Not Working 1 Answer