- Home /
Question by
DevonJavaScript · Jul 02, 2011 at 09:37 AM ·
playerfpsfloatwater
Floating Character, Water3
How would I make my character have full control and still float in water3, I have tried water3float but that controls my character to strongly and I would like it to were the user has alot more input. Any suggestions?
Comment
Can you include a link to 'water3float' so we have a clue what your are talking about?
Answer by amir_bobo · Jul 02, 2011 at 11:46 AM
I think i know what are you looking for! There is some sampel which can float rigidbody(s) whit "AddForce".
In your case (I suppose) u can use it like this;
enter code here
if(float)
{
Uplift = uplift;
}
else
Uplift = Vector3.zero;
controller.Move(moveDirection * Time.deltaTime - Uplift);
And this is the Floater Script:
using UnityEngine;
using System.Collections;
public class Floater : MonoBehaviour {
public float waterLevel, floatHeight;
public Vector3 buoyancyCentreOffset;
public float bounceDamp;
void FixedUpdate () {
Vector3 actionPoint = transform.position + transform.TransformDirection(buoyancyCentreOffset);
float forceFactor = 1f - ((actionPoint.y - waterLevel) / floatHeight);
if (forceFactor > 0f) {
Vector3 uplift = -Physics.gravity * (forceFactor - rigidbody.velocity.y * bounceDamp);
rigidbody.AddForceAtPosition(uplift, actionPoint);
}
}
}
UnTested! Hope be usefull!