Unity3D 漂浮效果,代码
using UnityEngine;using System.Collections;
public class Floater :
MonoBehaviour {
public float waterLevel, floatHeight;
public
Vector3 buoyancyCentreOffset;
public float bounceDamp;
void FixedUpdate () {
Vector3 actionPoint = trans<span href="tag.php?name=for" class="t_tag">for</span>m.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);
}
}
} {:soso_e179:} 好东西 好东西 很不错 楼主是超人 真心顶 不错不错 LZ真是人才 很不错 顶顶多好
页:
[1]