Question by
W1zzel · Dec 09, 2017 at 04:29 PM ·
scripting problemaddforcemovement scriptrigidbody.addforce
Need help for applying force to rigidbody with .AddForce
Hi there, i have a problem with adding Force to my Rigidbody.
I am using a movement that is relative to the cameras position.
However, the rigidbody does not move until i am using ForceMode.VelocityChange.
public float speed;
private Rigidbody rig;
private Animator anim;
public Camera cam;
// Use this for initialization
void Start () {
rig = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
if (cam == null)
{
cam = Camera.main;
}
}
void Update () {
Vector3 right = Vector3.Cross(Vector3.up, cam.transform.forward); Vector3 forward = Vector3.Cross(right, Vector3.up);
Vector3 movement = Vector3.zero;
movement += right * Input.GetAxis("Horizontal") * speed * Time.deltaTime;
movement += forward * Input.GetAxis("Vertical") * speed * Time.deltaTime;
rig.AddForce(movement, ForceMode.Impulse);
}
I am new to Programming, what am i doing wrong ? Thank you !
Comment
Your answer
Follow this Question
Related Questions
Bullet not moving rigidbody2d,AddForce not working for bullet 1 Answer
how to addtorque and addforce to same object? 0 Answers
How to make AddForce dash smoother, instead of teleporting 1 Answer
Noob Here... Can you please give Script for moving a object into random Direction. 0 Answers
Stop movement on collision 1 Answer