- Home /
 
how to rotate velocity/ tying movement to camera
I'm trying to make a simple ball-roller game, like the MB series-style games. i was using this tutorial: Tutorial
anyway, i finished it, and made some upgrades. But i can't figure out how to make the camera rotate! if i use a rotating camera script (which at first appears to work fine) the ball rotation control is still one-way!
basically, if i move the camera backwards, the ball controls still act like i'm faced forward, with forward going backwards, left - right, and so on.
i was wondering if i could, like, rotate the velocity, but i can't figure out a way to do that!
here is the code:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AddPlayerControlledVelocity : MonoBehaviour
 {
 
     [SerializeField]
     public bool UpPress;
     [SerializeField]
     Vector3 ForwardKeyAction;
     [SerializeField]
     KeyCode keyForward;
     [SerializeField]
     Vector3 BackwardKeyAction;
     [SerializeField]
     KeyCode keyBackward;
     [SerializeField]
     Vector3 RightKeyAction;
     [SerializeField]
     KeyCode keyRight;
     [SerializeField]
     Vector3 LeftKeyAction;
     [SerializeField]
     KeyCode keyLeft;
     public Vector3 jump;
     public float jumpForce = 3.0f;
     
     public bool isGrounded;
     Rigidbody rb;
     void Start(){
         rb = GetComponent<Rigidbody>();
         jump = new Vector3 (0.0f, 2.0f, 0.0f);
         UpPressed();
     }
 
     public void UpPressed ()
     {
         bool UpPress = true;
     }
     void OnCollisionStay(){
         isGrounded = true;
     }
     
     void FixedUpdate()
     {
         if (Input.GetKey(keyForward))
             GetComponent<Rigidbody> ().velocity += ForwardKeyAction;
 
         if (Input.GetKey(keyBackward))
             GetComponent<Rigidbody> ().velocity += BackwardKeyAction;
 
         if (Input.GetKey(keyRight))
             GetComponent<Rigidbody> ().velocity += RightKeyAction;
         
         if (Input.GetKey(keyLeft))
             GetComponent<Rigidbody> ().velocity += LeftKeyAction;
         if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
             rb.AddForce(jump * jumpForce, ForceMode.Impulse);
             isGrounded = false;
         if (UpPress == true)
             GetComponent<Rigidbody> ().velocity += ForwardKeyAction;
     }
 }
 
 
               Please Help!
*NOTE* I'm Using Unity 2018.4.26f1 and MonoDevelop 4.0.1, Mostly Because I have a old mac.
               Comment
              
 
               
              Your answer