- Home /
 
 
               Question by 
               keshav2010 · Dec 26, 2016 at 09:21 PM · 
                c#errorgetaxisforcesaddrelativeforce  
              
 
              How do i add RelativeForce in Z-Axis using InputManager and Input.GetAxis() method ? (read)
Okay, i know friends this is super easy but I'm facing a slightly different problem the object i want to move is in 0 Gravity and it is moving perfectly relative to its X-Y Axis but now i wanted to move it on Z-Axis too (relative to its own coordinate system and not world, so I'm using .AddRelativeForce() method )
but here a problem arises, I made a new Input Axis and named it as "Hyper" for no obvious reason and added ARROW-UP and ARROW DOWN as input buttons
after that, the script that I attached to object is is
 using UnityEngine;
 using System.Collections;
 public class characterController : MonoBehaviour {
     public float intensity;
     
     // Update is called once per frame
     void Update () {
         gameObject.GetComponentInParent<Rigidbody> ().AddRelativeForce (new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis("Vertical"),Input.GetAxis("Hyper"))*Time.deltaTime* intensity);
 
     }
 }
 
 
               but when I press arrow up and down, instead of moving toward Z-AXIS, the object moves in a YZ Axis (yea you can think of it as a path followed as such it forms 45-degree angle with Z-Axis)
               Comment
              
 
               
              Your answer