- Home /
The question is answered, right answer was accepted
Damping forces to stop boat oscillation
I have a boat that check 4 points to see if they are under water at any given time. When they are under water a force equal to the force required to hold the boat up dived by 4 plus an extra force that varies by depth(1/4 of the required boat force is applied at any point).
This works great to hold the boat up however the boat continually bounces between all 4 points very fast, i want this to happen but at a much slower rate to give the effect of boat bobbing/rolling. I would imagine that i need a damping force of some sort, any idea how i would go about it here is the code i have:
//finding the height above and below the water, downdist
// is the height above water, the 4 points are frontl for //front
// left point frontr for front right point,etc,etc
float distfl=floatheight-frontl.transform.position.y;
float distfr=floatheight-frontr.transform.position.y;
float distbr=floatheight-backr.transform.position.y;
float distbl=floatheight-backl.transform.position.y;
float downdistfl=frontl.transform.position.y-floatheight;
float downdistfr=frontr.transform.position.y-floatheight;
float downdistbr=backr.transform.position.y-floatheight;
float downdistbl=backl.transform.position.y-floatheight;
//36.75 is the force required to //hold up the boat dived by 4 from the 4 points //acceleration=force/mass 9.8*15=force,15 is mass,
//147=force to hold boat up,147/4=36.75
if (frontl.transform.position.y<floatheight){
boatr.AddForceAtPosition(Vector3.up*(36.75f+(distfl*36.75f)),frontl.transform.position);
}
if (frontr.transform.position.y<floatheight){
boatr.AddForceAtPosition(Vector3.up*(36.75f+(distfr*36.75f)),frontr.transform.position);
}
if (backl.transform.position.y<floatheight){
boatr.AddForceAtPosition(Vector3.up*(36.75f+(distbl*36.75f)),backl.transform.position);
}
if (backr.transform.position.y<floatheight){
boatr.AddForceAtPosition(Vector3.up*(36.75f+(distbr*36.75f)),backr.transform.position);
}
Has the answer been deleted? Does someone have another answer? :)
$$anonymous$$y crazy boat has oscillated, vibrated, and bounced for about 3 days, then I found this magical line of code (where boatRB is your Rigid Body):
boatRB.maxAngularVelocity = 0.5f;
...and the ship is now flowing like a swan on a calm lake :)
Follow this Question
Related Questions
Object buoyancy in water on different water levels? 1 Answer
Unexpected token if 1 Answer
Having trouble with player boat movement with buoyancy pack 0 Answers
Buoyancy Script Timing Inverted 1 Answer
Pro Water - Matching Rotation 0 Answers