I’m trying to make an iron man simulation in VR but I don’t know how I would make the player go the direction that his hand is facing. The code I have so far is this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flight : MonoBehaviour
{
public Transform rightController;
public Transform leftController;
private ParticleSystem rightControllerFlames;
private ParticleSystem leftControllerFlames;
public float moveSpeed;
public Rigidbody rb;
public AudioSource jetSound;
private bool flamesNotPlaying;
public Transform cam;
private void Awake()
{
rightControllerFlames = rightController.GetComponentInChildren<ParticleSystem>();
leftControllerFlames = leftController.GetComponentInChildren<ParticleSystem>();
}
private void Update()
{
if (leftControllerFlames.isPlaying == false && rightControllerFlames.isPlaying == false)
{
flamesNotPlaying = true;
jetSound.Stop();
}
else
{
flamesNotPlaying = false;
}
var rightControllerFlamesEmission = rightControllerFlames.emission;
var leftControllerFlamesEmission = leftControllerFlames.emission;
rightControllerFlamesEmission.rateOverTime = ButtonIsPressed.rightTriggerValue * 100;
leftControllerFlamesEmission.rateOverTime = ButtonIsPressed.leftTriggerValue * 100;
}
void FixedUpdate()
{
if (ButtonIsPressed.rightTriggerValue > 0.1f)
{
rightControllerFlames.Play();
jetSound.volume = ButtonIsPressed.rightTriggerValue;
if (!jetSound.isPlaying && !flamesNotPlaying)
{
jetSound.Play();
}
Vector3 forceVector = rightController.forward + rightController.right + rightController.up * ButtonIsPressed.rightTriggerValue * moveSpeed;
rb.AddForce(forceVector);
}
else
{
rightControllerFlames.Stop();
}
if (ButtonIsPressed.leftTriggerValue < 0.01f && ButtonIsPressed.rightTriggerValue < 0.01f)
{
if (jetSound.isPlaying)
{
jetSound.Stop();
}
}
if (ButtonIsPressed.leftTriggerValue > 0.1f)
{
leftControllerFlames.Play();
jetSound.volume = ButtonIsPressed.leftTriggerValue;
if (!jetSound.isPlaying && !flamesNotPlaying)
{
jetSound.Play();
}
Vector3 forceVector = leftController.forward + leftController.right + leftController.up * ButtonIsPressed.leftTriggerValue * moveSpeed;
rb.AddForce(forceVector);
}
else
{
leftControllerFlames.Stop();
}
}
}