1
\$\begingroup\$

How can I move a rigidbody to its facing direction? I've already tried this:

rigidbody.AddForce (transform.forward * v, ForceMode.Acceleration);
// v is a public float which gets a new value in Update function:
v = Input.GetAxis ("Vertical") * Speed;

in FixedUpdate, but it doesn't move forward. Movement of the cylinder It should go on that blue arrow, but it spins on the red arrow.

Hopefully u understood. Any suggestions?

\$\endgroup\$
2
  • \$\begingroup\$ how about Vector3.forward ? \$\endgroup\$
    – sertsedat
    Oct 15, 2014 at 13:53
  • \$\begingroup\$ is your objekt able to turn on the red arrow axis or other axis? if it isn't use vector3.forward \$\endgroup\$
    – Gorock
    Aug 14, 2015 at 22:24

2 Answers 2

1
\$\begingroup\$

Instead of using AddForce use AddRelativeForce

    rigidbody.AddRelativeForce (transform.forward * v, ForceMode.Acceleration);

    v = Input.GetAxis ("Vertical") * Speed;
\$\endgroup\$
0
\$\begingroup\$

My code works good. For example:

using UnityEngine;
using System.Collections;

public class AddForce : MonoBehaviour {

public Rigidbody myBody;
public float ForcePower;
public Vector3 myDirection;

// Use this for initialization
void Start () {
    myBody = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update () 
{

}

void FixedUpdate()
{
    myBody.AddForce(myDirection, ForceMode.Force);
}

}

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .