- Home /
Adding physics to various terrain
Is there a way to add physics to various terrain so that (for example) when your character is wading in water his speed becomes 80% of normal speed. Or when your character is wading through forest, 85%. You get the picture.
To clarify, I'm looking for a way to dynamically add physics to terrain. I haven't been able to find anything on the subject. It might be that I dunno what to look for, but any help is appreciated.
These things you are talking about... aren't physics. There is no such thing as a 'slow field' (as you seem to be talking about), as such, only substances with more or less friction. I think you should think carefully about what you are trying to do here, and make sure there isn't a better way (like manually defining trigger volumes, which cause different behaviours on the player).
Answer by aldonaletto · Oct 20, 2011 at 10:45 AM
As @syclamoth said, that's not a physics stuff: this should be implemented in the movement script of your character. If you use a CharacterController (most usual approach) you can define triggers for different terrain regions. For water, for instance, you can "bury" a cube under the water plane and adjust its dimensions to cover the whole water portion. Set isTrigger in the collider, and tag it as "Water". In the character script, add OnTriggerEnter and OnTriggerExit events and change the character speed according to the terrain - for instance:
var normalSpeed: float = 6.0; var waterSpeed: float = 4.5; var forestSpeed: float = 5.0; var inWater: boolean = false; var inForest: boolean = false;
function Update(){ // get the movement direction (see CharacterController.Move example) // move the character according to controls and region var speed = normalSpeed; if (inWater){ speed = waterSpeed; } else if (inForest){ speed = forestSpeed; } character.Move(moveDirection speed Time.deltaTime); }
function OnTriggerEnter(other: Collider){ if (other.tag == "Water"){ inWater = true; } else if (other.tag == "Forest"){ inForest = true; } }
function OnTriggerExit(other: Collider){ if (other.tag == "Water"){ inWater = false; } else if (other.tag == "Forest"){ inForest = false; } }
Your answer
Follow this Question
Related Questions
Why rotating the Terrain Collider does not work? 0 Answers
Modelling Terrain in Blender 1 Answer
Terrain having multiple textures 1 Answer
My object falls through terrain. 8 Answers
Terrain detail mesh material not working 0 Answers