How do I make bullets move at an angle?

So my character has 3 cannon tips to shoot from. The one in the middle goes straight right while the upper one goes upper right and the lower goes lower right. Currently all of them go straight right and I have no idea how to make the others move using their angles.
In the code I’m just instantiating the bullets and moving them using this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveObject : MonoBehaviour
{
    [SerializeField] float speed = 5f;
    [SerializeField] bool towardsRight = true;

    Rigidbody2D rb;

    void Start()
    {
        //Moving Object Using Rigidbody
        rb = GetComponent<Rigidbody2D>();
        if(!towardsRight)
        {
            rb.velocity = new Vector2(-speed, 0);
        }
       
        else
        {
            rb.velocity = new Vector2(speed, 0);
        }
    }

    public void setSpeed(float speed)
    {
        this.speed = speed;
    }

    public void setTowardsRight(bool towardsRight)
    {
        this.towardsRight = towardsRight;
    }

    public bool getTowardsRight()
    {
        return towardsRight;
    }

}

So I’m just using a speed value and adding it to the velocity.

Thanks for reading this :smile:

How are you shooting and moving your bullets currently? Post code

1 Like

Added in the thread :slight_smile: Sorry

You are only setting the x value of the velocity. Change speed to a float, angle the transforms they fire from, and then pass the direction of the transform and multiple it by the speed. For example;

rb.velocity = cannon.transform.right * speed;