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.
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;
}
}