Changing gravity with the fps controller (New to unity)

Hey everyone, So I’m fairly new to scripting in unity. I need to make the player rotate in relation to the world when certain keys are pressed, So far the closest I have been able to achieve is making the object rotate causing the player to fall flat on there face. The centre of gravity would need to change as I’m hoping to turn this into a multi-player game and changing the levels rotation would destroy the system. Despite the fact that i have had many previous programming experiences I am still very new to unity’s code and would appreciate if someone could also point me in the direction of where the code would need to be placed while using the default prefab. Thank you.

Turn gravity off for that object, then manually adjust the gravity based off of the orientation of the player.

function FixedUpdate () {
rigidbody.AddForce (transform.up * Physics.gravity);
}

When I use this I receive this error: “BCE0051: Operator ‘*’ cannot be used with a left hand side of type ‘UnityEngine.Vector3’ and a right hand side of type ‘UnityEngine.Vector3’.”

Physics.gravity.y will do it or alternatively cutting the whole transform.up part there and only using physcis.gravity as gravity does not care for your orientation at all

Okay, I have no idea what i’m doing anymore. Everything seems to give me errors so really hope someone can help me.

It’s the old fps preset code as I couldn’t do anything with the new one. I replaced there gravity with the rigid body one but it gives errors. Thanks

If you could, use code tags instead of quote tags, it makes reading it easier. :wink:

It seems the only error that was givin was the same one that you asked in a previous thread. (Which Dreamora gave the answer to)

var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;

private var moveDirection = Vector3.zero;
private var grounded : boolean = false;

function FixedUpdate() {
	if (grounded) {
		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;

		if (Input.GetButton ("Jump")) {
			moveDirection.y = jumpSpeed;
		}
	}

	//moveDirection.y -= gravity * Time.deltaTime;
	[COLOR="red"]rigidbody.AddForce (transform.up * Physics.gravity.y);[/COLOR]

	// Move the controller
	var controller : CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;
}

@script RequireComponent(CharacterController)

Thanks mate, I had completely the wrong idea about what dreamora said, Now I can run it but gravity seems to take no effect at all.