Change gravity on collision?

I’m trying to make a power up that makes it so when the player collides with a box, the gravity of the level changes. I have this for my code:

function OnTriggerEnter (other : Collider) {
	Physics.gravity = Vector3(0, -30, 0);
}

And I can’t get it to work. All I do is fall through the the box. Anyone have an idea of what to do?

P.S. I’m still pretty new to this so sorry if this is a stupid question :expressionless:

Make sure the collision is being detected. Your player needs a rigidbody and the collider needs to have isTrigger checked in the inspector.

If you just want to turn gravity off for your player you can use the useGravity property instead.

My character is a CharacterController, and isn’t a rigidbody. I have the isTrigger checked.

Take a look at the Unity Documentation regarding collisions.

Specifically this part:

"Triggers

An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below. "

I’ve read all that but I’m still really confused. I have an on trigger even that kills the player they collide with a platform. I took that exact script and just replaced the death part with this:

	Physics.gravity = Vector3(0, -30, 0);

But it doesn’t work. When I just apply the above script to something on the seen without the trigger the gravity changes. But when I put it with the platform that is a trigger, you just fall through and the gravity never changes

I am by no means smart or good at coding, but it seems if you wanted gravity to change and the character to go up, then the Y should go positive not negative. so maybe it should say. Physics.gravity = Vector3(0, 30, 0); just an idea. hope that helps.

Are you using the standard FPS controller prefab or your own script? If it is the former, that has gravity coded into it as of the last time I saw it; if it is the latter, please post your code using the code tags.