i want to make a game object (a cube) move in the direction of its head(any corner) when a button is pressed very much like a kite.i am new to controller scripting(i have the basic java knowledge) so ill be glad of any help .while to object is rotating in a circle ,the object must move in the direction of the head on the pres of a button.thanks in advance.
iam using this script
static var speed : int =5 ;
function Update ()
{
if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.LeftArrow)) transform.Translate (Vector3(-1,0,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.RightArrow)) transform.Translate (Vector3(1,0,0) * Time.deltaTime*speed);
}
static var speed : int = 5;
function Update ()
{
if (Input.GetKey (KeyCode.UpArrow))
transform.position.y = Mathf.Lerp (transform.position.y, transform.position.y + 1, Time.deltaTime * speed);
if (Input.GetKey (KeyCode.DownArrow))
transform.position.y = Mathf.Lerp (transform.position.y, transform.position.y - 1, Time.deltaTime * speed);
if (Input.GetKey (KeyCode.LeftArrow))
transform.position.x = Mathf.Lerp (transform.position.x, transform.position.x + 1, Time.deltaTime * speed);
if (Input.GetKey (KeyCode.RightArrow))
transform.position.x = Mathf.Lerp (transform.position.x, transform.position.x - 1, Time.deltaTime * speed);
}
if you are pressing a button and it does the reverse… try reversing the “-” and “+” marks one at a time
`Use inbuilt “Horizontal” & " vertical" axis
With
Float inputX= Input. GetAxis ("Horizontal");
Float inputZ = input.GetAxis (" Vertical");
Vector 3 direction = new Vector 3 ( inputX*speed* time.deltaTime, 0, inputZ*speed*Time. deltaatime)
Transfotm translate(direction);
There might be some errors or mistakes in this . So must google it once