I have a rigidbody character with 2 capsule objects to represent it’s hands. These hands are going to have thrusters attached to them to propel the character based on the direction and a float value of how much force is to be applied. The hands can rotate in all directions. I have attached a Debug.DrawRay in the picture that is longer depending on how much force to apply.
If both hands are pointing directly up, the character should be moved upward.
I know that I will probably need to provide more information to clarify the desired outcome, I am just not sure what information that will be at this stage. Below I have included my current code and an image of what I am trying to work with.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
Rigidbody rb;
public GameObject leftHand;
public GameObject rightHand;
public GameObject feet;
public GameObject thrustTarget;
public float playerHeight = 1.6f;
public float leftThrust = 0.0f;
public float rightThrust = 0.0f;
public float leftThrustMax = 100.0f;
public float rightThrustMax = 100.0f;
public float leftFuel = 100.0f;
public float rightFuel = 100.0f;
public float leftAcc = 10.0f;
public float rightAcc = 10.0f;
public float leftDec = 10.0f;
public float rightDec = 10.0f;
void Start () {
rb = GetComponent<Rigidbody>();
feet.transform.position = new Vector3(0,-playerHeight,0);
}
void Update () {
if(Input.GetKey("a")) {
leftThrust += leftAcc * Time.deltaTime;
} else {
leftThrust -= leftDec * Time.deltaTime;
}
if(Input.GetKey("d")) {
rightThrust += rightAcc * Time.deltaTime;
} else {
rightThrust -= rightDec * Time.deltaTime;
}
if(leftThrust > leftThrustMax) { leftThrust = leftThrustMax; }
if(rightThrust > rightThrustMax) { rightThrust = rightThrustMax; }
if(leftThrust < 0) { leftThrust = 0; }
if(rightThrust < 0) { rightThrust = 0; }
}
void FixedUpdate () {
Debug.DrawRay(leftHand.transform.position,-leftHand.transform.up * (leftThrust / 100),Color.red);
Debug.DrawRay(rightHand.transform.position,-rightHand.transform.up * (rightThrust / 100),Color.red);
}
}