- Home /
Strange issue, movement direction has been reversed when X axis is negative
I have 2 scripts which using camera as a transform for setting direction. The first one is for throwing ball in camera forward direction and this script works good.
public Transform forwards;
// Use this for initialization
void Start () {
GameObject _Go = GameObject.FindGameObjectWithTag("MainCamera");
GetComponent<Rigidbody>().AddForce(_Go.transform.forward * force, ForceMode.Impulse );
}
The second script is for ball movement.
void FixedUpdate()
{
{
Vector3 movement = Vector3.zero;
movement.x = ControlFreak2.CF2Input.GetAxis("Horizontal") * speed;
movement.y = ControlFreak2.CF2Input.GetAxis("Vertical") * speed;
if (movement.magnitude > 1)
{
movement.Normalize();
}
Vector3 rotatedDir = camTransform.TransformDirection(movement);
rotatedDir = new Vector3(rotatedDir.x, 0, rotatedDir.z);
rotatedDir = rotatedDir.normalized * movement.magnitude;
rb.AddForce(rotatedDir * speed);
As You can see, there's no problem to throwing ball to whatever direction but when the camera is pointed upward (camera X axis is negative) then movement direction has been reversed. https://www.youtube.com/watch?v=jhIBHKnu2eo&feature=youtu.be
Your answer
Follow this Question
Related Questions
Rotate according to the camera on Y and Z only! 2 Answers
Rotate Camera on axis and X axis not working 1 Answer
camera transform not working when getting axis position 3 Answers
Keep Camera from player at a certain distance while orbiting around player 2 Answers
How do I lock Y Axis movement for Parented Camera? 3 Answers