Hi, I have some code in an attempt to begin to model a plane but my problem is that the plane isn’t facing the direction that the force is being applied and I have no idea why.
public override void OnActionReceived(ActionBuffers actions)
{
pitch = actions.DiscreteActions[1];
yaw = actions.DiscreteActions[2];
rigidbody.AddTorque(transform.up * yaw * 50f);
rigidbody.AddTorque(transform.right * pitch * 50f);
rigidbody.AddRelativeForce(transform.forward * throttle * MaxThrottle);
}
public override void Heuristic(in ActionBuffers actionsOut)
{
var discreteActionsOut = actionsOut.DiscreteActions;
Vector3 forward = Vector3.zero;
Vector3 left = Vector3.zero;
Vector3 up = Vector3.zero;
yaw = 0f;
pitch = 0f;
if (Input.GetKey(KeyCode.W)) throttle += throttleIncrement;
else if (Input.GetKey(KeyCode.S)) throttle -= throttleIncrement;
throttle = Mathf.Clamp(throttle, 0f, 1f);
yaw += Input.GetAxis("Mouse X");
pitch += Input.GetAxis("Mouse Y");
discreteActionsOut[1] = pitch > 0 ? 1 : (pitch < 0 ? -1 : 0);
discreteActionsOut[2] = yaw > 0 ? 1 : (yaw < 0 ? -1 : 0);
}
Right now the problem isn’t with the AI itself, just some heuristic testing I’ve been trying
Any help would be appreciated