BEFORE YOU ANSWER PLEASE READ THE FOLLOWING
I don’t want to do any coding so please just give the code to me.
The code should either detect if a charter is in a box which defines water and makes it swimmable or the other way around not using y-axis as a determiner.
@Chase Does
Keep in mind that both the swimmer and the liquid object will need colliders attached and that the liquid collider will need to be a trigger.
public class Swimmer{//attach this to the character
public bool IsInWater;
public float Buoyancy;//I've found that a value of 4 results in perfect buoyancy
RigidBody rigidBod;
void Start(){
rigidBod = GetComponent<RigidBody>();
}
void FixedUpdate(){
if(IsInWater){
rigidBod.AddForce(0f, Buoyancy * -Physics.gravity.y, 0f);
//using swimming controls
}else{
//use normal controls
}
}
}
public class Liquid{//attach this to the liquid
void OnTriggerEnter(Collider other){
Swimmer swimmer = other.gameObject.GetComponent<Swimmer>();
if(swimmer != null){
swimmer.IsInWater = True;
}
}
void OnTriggerExit(Collider other){
Swimmer swimmer = other.gameObject.GetComponent<Swimmer>();
if(swimmer != null){
swimmer.IsInWater = False;
}
}
}
how do you attach the script to the player and liquid???