Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How do i add force to a certain direction based on my players direction

Discussion in 'Physics' started by S3atbelts, Nov 12, 2022.

  1. S3atbelts

    S3atbelts

    Joined:
    Feb 5, 2022
    Posts:
    2
    i am trying to make a shotgun jump where i press left mouse button and it shoots me backwards but i dont know how to. it would be really apreciated if you could help i just want the code inside the if statement
    this is my my code

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class ShotgunJump : MonoBehaviour
    7. {
    8.     public Rigidbody rb;
    9.     public Transform orientation;
    10.    
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         if (Input.GetMouseButtonDown(0))
    16.         {
    17.            
    18.         }
    19.     }
    20. }
    21. [CODE/]
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
  3. S3atbelts

    S3atbelts

    Joined:
    Feb 5, 2022
    Posts:
    2
    the code worked but not in thw way i wanted all it did was push me on the z axis but i wanted to be able to shoot me back in whatever direction i was facing, e.g if i looked down it would shoot me up.

    thanks anyway.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    ok then need to take -transform.forward from the gun