简体   繁体   English

Unity2D中的旋转

[英]Rotation in Unity2D

Is it possible to move a game object from one side of the screen to the other, but have it rotating in a circle at the same time?? 是否可以将游戏对象从屏幕的一侧移到另一侧,但同时使其旋转一圈?

For example, I'm using this code to move the object: 例如,我正在使用以下代码移动对象:

Vector3 carPos = new Vector3 (transform.position.x, Random.Range (7.09f, -6.63f), transform.position.z);

How can I get the object to rotate 360 degrees on its axis over say 2 seconds?? 我如何才能使对象绕其轴旋转360度(例如2秒钟)? I tried playing around with z positions but it makes move in a circle only and not across the screen. 我尝试在z位置上玩耍,但是它只能绕一个圆圈移动,而不能跨屏幕移动。

you can use the Animation in unity to rotate your object, you can configure the time and velocity 您可以统一使用“动画”旋转对象,可以配置时间和速度

https://unity3d.com/learn/tutorials/topics/animation https://unity3d.com/learn/tutorials/topics/animation

Use transform.position = Vector3.Lerp(A, B,...) to move the object from Point A to point B. At the same time (and i'm not sure if i understand you correct) use transform.Rotate(0, 0, speed * Time.deltatime) to rotate your Object around z. 使用transform.position = Vector3.Lerp(A,B,...)将对象从点A移到点B。同时(而且我不确定我是否理解正确)使用transform.Rotate( 0、0,速度* Time.deltatime)围绕z旋转对象。 Put both in the Update Loop. 将两者都放入更新循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM