# Rotational Gravity - Camera and Force problems

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.

Ok, if you are going to go with my way then start simple! Then build upon these working foundations.

For some info on how to align your player rotation for your current player position in relation to your gravitational pull/push vector position take a look at my answer to this :

You will be pushing away rather than pulling toward!!! This script shows you how to keep the player object correctly aligned in terms of rotation for you current position in relation to the gravitational position vector. You will still need to apply your gravity force in the right direction for current position in relation to your gravity point position.

For the curved connecting sections it will probably be best to model the curve connections in a 3D package such as Blender. You will put the anchor point of the connection mesh section at the point where you want the gravity calculations to adhere to. Then use a trigger script to switch between the cylinder section central line gravity point and the connection(semi spherical) gravity point.

Once you have this working you can then start to reintroduce the complex FPS controller attributes.

As stated above, if done this way then apart from the enemy object AI(relating to intelligent movement) the basic scripts that you write here for gravity etc will be directly transferable to your enemy objects.

Hope this helps