Question by
gmod622 · Jan 22, 2017 at 12:01 AM ·
rotationrigidbodyquaternion
[VR] Rigidbody.AddForce() following controllers rotation
Hey there!
So I have a spawnpoint attached to the right controller, however when the shoot action is triggered, it seems that the Vector3.forward shoots it in a static direction, no matter where the controller is. How would I fix this? Here is the code:
public class Shoot : MonoBehaviour {
private SteamVR_TrackedObject trackedObj;
private SteamVR_Controller.Device device;
public Rigidbody bullet;
public Transform bulletStart;
public int force = 500;
void Start()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Update()
{
device = SteamVR_Controller.Input((int)trackedObj.index);
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
device.TriggerHapticPulse(1000);
Rigidbody rigidPrefab;
rigidPrefab = Instantiate(bullet, bulletStart.transform.position, bulletStart.transform.rotation) as Rigidbody;
rigidPrefab.AddForce(Vector3.forward * force);
}
}
}
Comment