代码 控制unity 暂停 编辑器_Unity3D研究院之使用Animation编辑器编辑动画(五十四)...

MoMo,请教个问题,我用系统自带的Camera控制脚本,想做第三人称,但是人物要固定在摄像机左边,就是屏幕偏左的地方。现在我旋转视角,人物就会到屏幕中间的位置上。void LateUpdate(){finalDist = desDist;// Horizontal smooth rotationxAngl = Mathf.LerpAngle(cam.eulerAngles.y, hero.eulerAngles.y, 0);// Vertical angle limitationyAngl = ClampAngle(yAngl, minAngleY, maxAngleY);// Camera rotationQuaternion camRot = Quaternion.Euler(yAngl, xAngl, 0);// Camera heightVector3 headPos = new Vector3(0, -heroHeight /1.2f, 0);// Camera positionVector3 camPos = hero.position – (camRot * Vector3.forward * desDist headPos);// Recalculate hero positionVector3 trueHeroPos = new Vector3(hero.position.x, hero.position.y heroHeight, hero.position.z);// Check for collision with LinecastRaycastHit hit;bool isOk = false;if ( Physics.Linecast(trueHeroPos, camPos – Vector3.up Vector3.forward, out hit, collisionLayers.value)) // slightly behind and below the camera{// Final distancefinalDist = Vector3.Distance (trueHeroPos, hit.point) – offsetFromWall;isOk = true;}// Lerp current distance if not correctedif ( !isOk || ( finalDist > curDist ) )curDist = Mathf.Lerp (curDist, finalDist, Time.deltaTime * zoomDampening);elsecurDist = finalDist;// Recalculate camera positioncamPos = hero.position – (camRot * Vector3.forward * curDist headPos);// Apply XY-axisif(Mathf.Abs(joystickR.outputXY.x) < Mathf.Abs(joystickR.outputXY.y)){yAngl -= joystickR.outputXY.y * ySpeed;bPlayerRotate = false;// Apply position and rotationcam.rotation = camRot;cam.position = camPos;}else if(Mathf.Abs(joystickR.outputXY.x) > Mathf.Abs(joystickR.outputXY.y)){float rotateStep = joystickR.outputXY.x * xSpeed;controller.transform.RotateAround(transform.position, Vector3.up, rotateStep);if(joystick.outputXY.x == 0 && joystick.outputXY.y == 0){if(joystickR.outputXY.x < 0){playerAnimation.AnimationLeftMove();}else if(joystickR.outputXY.x > 0){playerAnimation.AnimationRightMove();}}bPlayerRotate = true;}else{bPlayerRotate = false;}}//这段代码基本都是U3D自带的,我自己的代码在// Apply XY-axis这里if(Mathf.Abs(joystickR.outputXY.x) < Mathf.Abs(joystickR.outputXY.y))//这里是视角上下移动else if(Mathf.Abs(joystickR.outputXY.x) > Mathf.Abs(joystickR.outputXY.y))//这里是控制角色左右旋转的,我没有控制camera,因为角色动,然后绑定的camera也会左右旋转问题是,不管是上下左右移动joystickR,主角都会回到屏幕中间,而我想要的效果是,主角一直在屏幕偏左的位置,不要回到中间。谢谢啦,大神momo。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值