I am trying to get zero g movement using the oculus ovr controller. Currently this is part of VR Interaction Framework by BNG. I know that the character controller can be made to simulate swimming and even flying, but I cannot get zero g movement out of it. I have tried to add a rigidbody and set it to kinematic and set the character controller movescale = 0 and gravity = 0. That works by suspending the player in the air, allows the player to move around like when on the ground.
So what is my question? My question is, How do I get the velocity of pushing off a gripped object to go to the rigidbody velocity and get zero g movement?
I know that this is possible, but how to make the player use the rigidbody instead of the character controller.
Here is my current code that currently only turns off gravity, but will not make the player move in a zero g atmosphere.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace BNG
{
public class ZeroG : MonoBehaviour
{
OVRPlayerController pControl;
BNGPlayerController bngController;
CharacterController characterController;
public Rigidbody rb;
public bool GravityEnabled = true;
private void Start()
{
pControl = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<OVRPlayerController>();
bngController = GameObject.FindGameObjectWithTag("Player").GetComponent<BNGPlayerController>();
characterController = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<CharacterController>();
}
void OnTriggerEnter(Collider other)
{
if (other.GetComponent<CharacterController>())
{
ChangeGravity(false);
pControl.ZeroG();
rb.useGravity = false;
//rb.isKinematic = true;
float overallSpeed = characterController.velocity.magnitude;
// Vector3 moveDirection = transform.forward * overallSpeed;
Vector3 moveDirection = new Vector3(characterController.velocity.x, characterController.velocity.y, characterController.velocity.z);
//characterController.Move(moveDirection * Time.deltaTime);
rb.velocity = moveDirection * Time.deltaTime;
}
if (other.GetComponent<Rigidbody>() && !other.GetComponent<CharacterController>())
{
other.attachedRigidbody.useGravity = false;
}
}
public void ChangeGravity(bool gravityOn)
{
GravityEnabled = gravityOn;
bngController.GravityEnabled = gravityOn;
}
void OnTriggerExit(Collider other)
{
if (other.GetComponent<CharacterController>())
{
ChangeGravity(true);
pControl.NormalG();
rb.useGravity = true;
// rb.isKinematic = true;
}
if (other.GetComponent<Rigidbody>() && !other.GetComponent<CharacterController>())
{
other.attachedRigidbody.useGravity = true;
}
}
}
}
Small video of what it looks like in game.