简体   繁体   English

unity 2d 如何在x轴上平移+旋转而不影响y轴

[英]Unity 2d how to translate on the x axis + rotate without affecting y axis

I have an object that spawns at the far right of the screen that I would like to travel across the screen to the left.我有一个生成在屏幕最右侧的对象,我想穿过屏幕向左移动。 The issue I am having is adding rotation to the object while having it travel left at the same time.我遇到的问题是在对象向左移动的同时向其添加旋转。 What is happening is as the object is rotating its left value is also changing so the object just goes in a circle.发生的事情是当对象旋转时,它的左值也在变化,所以对象只是绕了一圈。 What is the best way to keep this object on a straight path while adding rotation?在添加旋转时保持该对象在直线路径上的最佳方法是什么?

        transform.Rotate(0, 0, rotateSpeed * Time.deltaTime);
        transform.Translate(Vector2.left * 5 * Time.deltaTime);

也许将 Space.World 添加到翻译中

transform.Translate(Vector2.left * 5 * Time.deltaTime,Space.World);

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

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