I’m a beginner to coding and I’ve downloaded a free UI joystick asset and I’m trying to use it to control the direction that my player is shooting (Top down view)
It works well when used for movement, but with shooting the issue is that on lower sensitivities the bullets velocities vary. Basically I need to propel a projectile at the angle of the joystick at a consistent force
Here is the code
Vector3 shoot;
public VariableJoystick shootJoystick;
void update()
{
shoot = Vector2.right * shootJoystick.Horizontal + Vector2.up * shootJoystick.Vertical;
if(shootJoystick.Vertical != 0 || shootJoystick.Horizontal != 0)
{
joyAttack();
isShooting = true;
}
if (shootJoystick.Vertical == 0 && shootJoystick.Horizontal == 0)
isShooting = false;
}
void joyAttack()
{
GameObject newbullet = Instantiate(bullet, transform.position, transform.rotation);
newbullet.GetComponent<Rigidbody2D>().AddForce(shoot * shotpower);
}