# Vector questions for a wall-riding vehicle game.

Hey all,

I’m writing a vehicle game for a school project in which the vehicle can climb the walls (the vehicle is a giant wheel).

I’ve made some headway on the scripting but I have two questions, hopefully someone can answer them.

#1
__

Is there anyway to change the direction that gravity pull down on, as far as Rigidbodys are concerned. I obviously want to have gravity always be in the direction opposite of the vehicles local up direction. Didn’t see much about gravity in the Rigidbody documentation.

#2
__

Since I’m using a sphere collider to handle acceleration and rotation on my vehicle, I find myself needing to keep a local up and forward vector in the control script that is independent of the current Transform (The spinning of the wheel via the sphere collider seems to muck with the Transform’s forward vector).

The up vector is simple, I am just raycasting downward, and taking the surface normal.

However, keeping a local forward vector is proving to be a problem. Theres probably a simple way to do this in Unity, but I just can’t think of a higher level way to do it. The local forward vector is simply the positive Z axis in object space, but I’m not sure how to access that?

If anyone has any advice I would greatly appreciated it. I’m used to doing things at a much lower level in straight DirectX or XNA.

-Bruno Sommer

Hello Whirlwind,

According to the documentation you can change the gravity vector on the fly.

``````Physics.gravity = Vector3(0, -1.0, 0);
``````

You can also turn it on and off for an individual object.

``````Rigidbody.useGravity = false;
``````

You can find the rigidbody documentation here.

If you’re making some sort of racing game where multiple game actors need an individualized gravity vector, might I suggest turning off gravity all together in the project settings and faking it with your own localized force.

Make the wheel a child of an empty game object, which doesn’t rotate. Then you just move the empty around, rather than the wheel, and the spinning won’t mess with forward vectors or anything.

–Eric