how do i make a room (collision) that gives me more gravity or less or turn mewith my head to the ground
could some1 help me with this ?
If you want to change the physics based gravity, just create a collider that matches your room and set it to trigger. Then create a script for your player object which contains the below code.
//If player enters the room set a higher gravity
function OnTriggerEnter(col : Collider){
if(col.name == "YourRoomName"){
Physics.gravity = Vector3(0, -30, 0);
}
}
//As soon as player exits the room set a different gravity
function OnTriggerExit(col : Collider){
if(col.name == "YourRoomName"){
Physics.gravity = Vector3(0, -1, 0);
}
}
You can manipulate gravity freely, like any other property of the physics engine. For turning you head towards the ground (e.g when falling freely) I would attach a rigidbody to the head and probably another rigidbody to the body. Make the head heavy (can be easy when working in Unity and tweak from there.
HTH
uhm this script looks good but it is full of error
could you help me ?
My bad, please change Function to function. Old habits die hard If you encounter any other errors please write down the errors too.
awesome thanks man !
you rock !
how does it work ?
i made an empty game object called Room (same name as in script)
attached script to player
give ther Room object a collission
but i cant go trough it it just works as a wall what to do ?
Set the collider you have added to your room as Trigger. You can see it in the inspector window when you select your room, it’s a tick box.
Also don’t forget to change the “YourRoomName” in the given script to same name as your room object. If it’s name is Room then change it to Room in script.
i did it but i dont see whats changed
how do i make it that i cant jump there anymore because of the gravity ?
wich codes do i have to do ?
It all depends on what kind of character you have. Do you use Character Controller or a Rigidbody in your main character? Physics.gravity only affects rigidbodies as they are the physics objects. If you want to alter your character controller, you simply change your gravity variable in the OnTriggerEnter and OnTriggerExit functions.
i got character controller
how to do that ?
You just change the gravity variable in the script where you control your character using the above code. Don’t expect other people to write code for you, if it’s too hard to figure out even when people give you code, maybe you should start with something simpler or maybe tutorials. I’m not trying to be a d*ck here, just helping you out.
your right sorry
but i already done the script now but
thank you all people who helped me
thank you mortiis and sorry your right
nalim