Launching an object in the direction it's moving

void FixedUpdate()
{
//Movement
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”);

        Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);

        rb.AddForce(movement * speed);

        //launch player
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.velocity = new Vector3(0,0,launchSpeed);
        }

The player is a rolling ball(rigidbody). I’m fine with the current movement but i’m trying to make the player launch in the direction it’s moving when I press space. How do i do this?
Thanks! :slight_smile:

Hi, the “direction it’s moving” is contained in the rigidbody’s velocity. So, if you want to create an impulse in the direction the rigidbody is already moving, you can use rigidbody.AddForce( rigidbody.velocity.normalized * impluseSpeed ).