真Unity3d_人物摇杆操作

一开始。。。。。一卡一顿的,人物很飘

public Vector3 TickMove(){
			float fThisMoveSpeed = EntityFSMMoveSpeed;
			Vector3 sThisSyncDir = EntityFSMDirection;
			if (m_pcGOSSI.fLastSyncSecond == 0) {
				m_pcGOSSI.fLastSyncSecond = Time.realtimeSinceStartup;
//				sThisSyncDir.z +=45;
			}
			float fSyncSecond = m_pcGOSSI.fLastSyncSecond;
			RealEntity.PlayerRunAnimation();
			Vector3 realPos2D = new Vector3(objTransform.position.x, 60, objTransform.position.z);


			//float fAngle = Vector3.Angle(sThisSyncDir, m_pcGOSSI.sLocalSyncDir);
			//位置计算
			float fThisRealTimeSinceStartup = Time.realtimeSinceStartup;
			//float fThisFrameTimeSpan = fThisRealTimeSinceStartup - m_pcGOSSI.fLastSyncSecond;
			float fThisFrameTimeSpan = fThisRealTimeSinceStartup - fSyncSecond;
			float fThisSyncDist = fThisMoveSpeed * fThisFrameTimeSpan;
	
			Vector3 sNewPos = sThisSyncDir * fThisSyncDist + realPos2D;
			if (sNewPos.magnitude > 0)
			{

				objTransform.position = sNewPos;
			}


			GameMethod.GetMainCamera.FixedUpdatePosition();
			m_pcGOSSI.fLastSyncSecond = fThisRealTimeSinceStartup;
			return sThisSyncDir;

		}


加了时间因子之后

双线程渲染

(一开始tickmove()方法放在某触发器下,发现并不均匀,现在放在LateUpdate事件里面即可,因为LateUpdate的时间因子是固定的,移动起来看上就不卡了)

例如:currentTime += Time.deltaTime; //这里的deltaTime是固定的


由于45度镜头,需要再调整方向夹角()

public void TickRotate(Vector3 sThisSyncDir){
			sThisSyncDir = 15 * sThisSyncDir;//乘大15并没有什么作用,暂时发现这句代码没用的,只是测试用	

			Quaternion DestQuaternion = Quaternion.LookRotation(sThisSyncDir);

			Quaternion sMidQuater = Quaternion.Lerp(objTransform.rotation, DestQuaternion, 3 * Time.deltaTime);//在from和to之间插值旋转.
			objTransform.rotation = sMidQuater;

		}


public Vector3 TickMove(){
			float fThisMoveSpeed = EntityFSMMoveSpeed;
			Vector3 sThisSyncDir = EntityFSMDirection;
			if (m_pcGOSSI.fLastSyncSecond == 0) {
				m_pcGOSSI.fLastSyncSecond = Time.realtimeSinceStartup;
//				sThisSyncDir.z +=45;
			}
			float fSyncSecond = m_pcGOSSI.fLastSyncSecond;
			RealEntity.PlayerRunAnimation();
			Vector3 realPos2D = new Vector3(objTransform.position.x, 60, objTransform.position.z);

			//Vector3 sThisSyncDir = realPos2D;
			//Vector3 sThisSyncDir = sCrossPoint - realPos2D;
			//sThisSyncDir.y = 0;
			//sThisSyncDir = this.ConvertVector3ToDir (sThisSyncDir);//转换角度
			//不使用单位向量,摇杆幅度越大,应该速度会越快
			sThisSyncDir.Normalize();
			sThisSyncDir = Quaternion.AngleAxis(-45, Vector3.up) * sThisSyncDir;

			//float fAngle = Vector3.Angle(sThisSyncDir, m_pcGOSSI.sLocalSyncDir);
			//位置计算
			float fThisRealTimeSinceStartup = Time.realtimeSinceStartup;
			//float fThisFrameTimeSpan = fThisRealTimeSinceStartup - m_pcGOSSI.fLastSyncSecond;
			float fThisFrameTimeSpan = fThisRealTimeSinceStartup - fSyncSecond;
			float fThisSyncDist = fThisMoveSpeed * fThisFrameTimeSpan;
	
			Vector3 sNewPos = sThisSyncDir * fThisSyncDist + realPos2D;
			if (sNewPos.magnitude > 0)
			{

				objTransform.position = sNewPos;
			}


			GameMethod.GetMainCamera.FixedUpdatePosition();
			m_pcGOSSI.fLastSyncSecond = fThisRealTimeSinceStartup;
			return sThisSyncDir;

		}



缺少打击感

对于mmoa,王者荣耀之流的游戏,重在操作流畅和技能准确性,以及服务器和网络的稳定,对实际镜头效果需求不大,一般的镜头即可

最终预计采用《武士2》的后摇镜头






参考资料:

北京unity3d创业团队,对技术有研究,VR,C#等。。。。不错的说

http://blog.csdn.net/sxbluebird/article/details/43225401

发布了294 篇原创文章 · 获赞 52 · 访问量 78万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览