找回密码
 立即注册
楼主: 暴躁小强

[特效] Unity3D 漂浮效果,代码

  [复制链接]
发表于 2012-6-5 13:52 | 显示全部楼层 |阅读模式
  1. using UnityEngine;
  2. using System.Collections;

  3. public class Floater :
  4. MonoBehaviour {
  5.     public float waterLevel, floatHeight;
  6.     public
  7. Vector3 buoyancyCentreOffset;
  8.     public float bounceDamp;
  9.    
  10.    
  11.   
  12.   void FixedUpdate () {
  13.         Vector3 actionPoint = trans<span href="tag.php?name=for" class="t_tag">for</span>m.position +
  14. transform.TransformDirection(buoyancyCentreOffset);
  15.         float forceFactor
  16. = 1f - ((actionPoint.y - waterLevel) / floatHeight);
  17.       
  18.         if
  19. (forceFactor > 0f) {
  20.             Vector3 uplift = -Physics.gravity *
  21. (forceFactor - rigidbody.velocity.y * bounceDamp);
  22.            
  23. rigidbody.AddForceAtPosition(uplift, actionPoint);
  24.         }
  25.     }
  26. }
复制代码

评分

参与人数 1 +2 收起 理由
graywolfx21 + 2 赞一个!

查看全部评分

发表于 2014-1-13 19:34 | 显示全部楼层
{:soso_e179:}
发表于 2014-5-8 14:19 | 显示全部楼层
好东西 好东西
发表于 2017-4-22 15:06 | 显示全部楼层
很不错
发表于 2017-4-22 14:47 | 显示全部楼层
楼主是超人
发表于 2017-4-22 14:37 | 显示全部楼层
真心顶
发表于 2017-4-22 15:14 | 显示全部楼层
不错不错
发表于 2017-4-22 15:13 | 显示全部楼层
LZ真是人才
发表于 2017-4-28 15:09 | 显示全部楼层
很不错
发表于 2017-4-28 14:35 | 显示全部楼层
顶顶多好
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-27 19:46 , Processed in 0.276981 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表