- Home /
translate method dont work with rotate method
here is my question when i want rotate my object contniously the translate method not work
i mean my object never translate and in addition this two method not work with each other
what ican di ?
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public float EnemySpeed;
// Use this for initialization
void Start () {
gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 28);
}
// Update is called once per frame
void Update ()
{
gameObject.transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed);
gameObject.transform.Rotate(Vector3.up * 30);
if (gameObject.transform.position.z < -88)
{
Destroy(gameObject);
}
//gameObject.transform.Rotate(Vector3.up * 10);
}
void OnTriggerEnter(Collider colide)
{
Destroy(gameObject);
}
}
thanks for formatting learn how to do that but what about my question
Answer by Kryptos · Aug 14, 2012 at 01:30 PM
Not sure to understand what you are trying to achieve.
gameObject.transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed);
This line will make your object translate relatively to its local left
vector. But since it also rotates each frame around the local y-axis, the translation direction will always be different. Therefore it looks like the translation never occured.
If you want to translate on the same direction (here Vector3.left), you should use this code instead:
transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed, Space.World);
Now, the rotation does not use the framerate which is not consistent. Consider using this code instead:
transform.Rotate(Vector3.up * Time.deltaTime * 30, Space.Self);
This will make your object rotate by 30 degrees per second around the local y-axis. Note that Space.Self
is a default value, but it is better to set it explictly so that mistakes can be avoided.
my friend you are god that is best explain that ever i hear
so the default in transform is local is that right ?
so if i have question how can directly ask you ?
@robertofantasy the default is these two particular methods is local. You can find that information in the documentation.
You cannot ask me directly: the purpose of this website is to be a knowledge database. Everyone can learn from other errors/mistakes/issues.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075644im_/https://answers.unity.com/themes/thub/images/avi.jpg)