I’m trying to emulate the rotational gravity that would exist on a cylindrical space station as such
I am attempting to do so buy this method…
find the player z, then draw line from the center of cylinder with the same z to the player. Apply force in that direction then rotate player with the cylindrical center defined as up
public class rotationalGravity : MonoBehaviour {
public GameObject player;
Vector3 middlePoint;
Vector3 playerV;
Vector3 playerPos;
Vector3 forceDirection;
Rigidbody playerRidge;
void Start () {
playerV = player.transform.position;
middlePoint = new Vector3 (0, 0, playerV[2]); // sets middle point to have same z as player
playerRidge = player.AddComponent<Rigidbody>(); // causes player to shoot up for some reason
}
void Update () {
playerPos = new Vector3 (playerV [0], playerV [1], playerV [2]);
middlePoint.z = playerV [2];
forceDirection = middlePoint + playerPos; // gets direction to apply force?
//Physics.gravity = forceDirection;
player.transform.Rotate (Vector3.forward * Time.deltaTime); // another way i was trying to rotate player
playerRidge.transform.forward = Physics.gravity; // trying to rotate player around the center of cylinder
playerRidge.AddForce(-forceDirection * Time.deltaTime); // supposed to apply force to player in the direction from the middle
When it runs the player(which is the default FPS Controller) just floats up and passes through everything.
The camera rotation is way off too. Do I need to make changes to the FPS Controller to get the camera and controls to rotate correctly? And what am I doing wrong in trying to apply the force to the player? This project is being made to learn a lot of the ropes.
EDIT: I’d rather implement a system of this style rather than rotate the cylinder as down the line there will be multiple enemies and potential a second player.