Not to move the whole object to the right or left but to move it to the spin direction.
In this short video clip i recorded the cylinder is moving to the right but also seems to move to the camera to my direction i mean it looks like it’s moving to the left and backward together.
But i want it to move to the right or left on the spin axis and not like it is in the video.
Just directly to the right or left and keep it spin.
I want to move it to the right or left and not also to the backawrd i mean to the camera direction.
This is the script:
using UnityEngine;
using System.Collections;
public class MakeTwoPoints3D : MonoBehaviour
{
public float speed = 2.0f;
public float moveSpeed = 5.0f;
void Start()
{
}
void Update()
{
transform.Rotate(Vector3.up, speed * Time.deltaTime);
transform.position += Vector3.right * Time.deltaTime * moveSpeed;
}
}
The only reason the up Code works is the your object’s up is the same as the world up. if you ever tilted your object (had it lean forward or back) it wouldn’t spin right either.
Vector3.right is relative to the world coordinate system, but you cylinder is not aligned with that. You can either add transform.right to the position or use transform.Translate(Vector3.right, Space.Self). But, when the object is rotating, this relative direction will rotate with it, so this will also not give you what you want. You will have to separate the rotation and the translation: parent the cylinder to an empty gameobject. The cylinder keeps rotating, and the parent moves (as outlined above using either a vector relative to its own orientation or the Translate function which can be calculated in the local coordinate system)