# Centric gravity issues...

'allo, I'm trying to finish this gravity system, but the character never wants to be attracted to my game object. Instead, it keeps getting attracted to the world origin. Here are the segments in question:

``````public GameObject centricGravityTarget;
``````
``````else if (gravityMode == 2) {
if (Physics.Raycast((transform.position + transform.up),(centricGravityTarget.transform.position + transform.position).normalized * -1, out hit, gravityField, groundLayers.value)) {
desiredUp = (centricGravityTarget.transform.position + transform.position).normalized;
}
}
``````
``````else if (gravityMode == 2) {
Vector3 gravityDir = centricGravityTarget.transform.position + transform.position;
gravityDir = gravityDir.normalized;
}
``````

I suspect that the former will work once the latter works.

Thanks!

Ok, your problem with both appears to be you are adding/subtracting backwards for what you are trying to accomplish.

For the first one, I had a little trouble figuring out exactly what you are doing, I think you are sending a ray towards the planet to get the normal so that you can align the rotation correctly. So here is what I came up with. The trick is to subtract the player's position from the attractor instead of add them and flip the sign. Think of it like this. 5 - 2 != -(5 + 2)

``````    RaycastHit hit;
if (Physics.Raycast((transform.position + transform.up),(centricGravityTarget.transform.position - transform.position).normalized, out hit)) {
desiredUp = hit.normal;
print (desiredUp);
}

``````

The second one had a nearly identical problem. So here it goes.

``````        //subtract instead of add and multiply by positive gravity in the last step.
Vector3 gravityDir = centricGravityTarget.transform.position - transform.position;
gravityDir = gravityDir.normalized;