- Home /
Question by
unity_PfUCJ6Cm1seBtQ · Jul 25, 2019 at 09:53 PM ·
rigidbodyinputvraddforce
GetComponent.Addforce() not working
I tried both the ways but its not working I am using unity 2019.6.0a3 GVR-1.200.1
public float speed = 4.5f;
public float MovementAmplitude = 0.1f;
public float MovementFrequency = 2.25f;
public float JumpingForce = 450f;
// Start is called before the first frame update
void Start()
{
//transform.position = new Vector3(-3.21f, 3.833f, -38.004f);
}
// Update is called once per frame
void Update()
{
transform.position += speed * Vector3.forward * Time.deltaTime;
transform.position = new Vector3(
transform.position.x,
Mathf.Cos(transform.position.z * MovementFrequency)*MovementAmplitude,
transform.position.z
) ;
//GvrPointerInputModule.Pointer.TriggerDown ||
if (Input.GetKeyDown("space"))
{
Debug.Log("SPace is pressed");
Debug.Log(GetComponent<Rigidbody>());
//GetComponent<Rigidbody>().AddForce(Vector3.up * JumpingForce);
Rigidbody rb = GetComponent<Rigidbody>();
rb.AddForce(Vector3.up * JumpingForce);
}
}
Comment
Answer by Arpi01 · Jul 25, 2019 at 11:09 PM
It probably is a problem cause due to you hardcoding the movement on the transform, it is rewriting the y position, so the force is applied but is not able to move it, if you are going to program the movement on the rigid body, everything should be on the rigid body, and if it is going to hardcoded in the transform, leave it all in the transform