- Home /
Why the spaceship is moving forward and not up ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Landing : MonoBehaviour
{
public float speed = 3.0f;
public Vector3 direction = Vector3.up;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
transform.Translate(direction * speed * Time.deltaTime);
}
}
Vector3.up is (0, 1, 0) and 1 is the y so it should move up slowly but instead it's moving forward. What am i missing here ?
if you click on the object with move tool those the green arrow pointing in the direction you want to move the object?
I did a test. The z axis is changing up/down not the y (0,0,1)
Transform.translate by default works in the local coordinate system. You can change this by adding the Space.World parameter, and it should work fine.
Seems like this is a camera problem. It's likely that in your camera view "up" is actually Z (or perhaps X) coordinate. You could just try to change the direction to Vector3.forward and see if that solves it.
I did something else now. If i'm using Lerp then up will move the spaceship up.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Landing : $$anonymous$$onoBehaviour
{
public Vector3 startPos;
public Vector3 endPos;
public float distance = 30f;
public float lerpTime = 5;
public float currentLerpTime = 0;
// Use this for initialization
void Start ()
{
startPos = transform.position;
endPos = transform.position + Vector3.up * distance;
}
// Update is called once per frame
void Update()
{
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
currentLerpTime = lerpTime;
float Perc = currentLerpTime / lerpTime;
transform.position = Vector3.Lerp(startPos, endPos, Perc);
}
}
Answer by tormentoarmagedoom · Sep 24, 2017 at 01:42 PM
Hello @Chocolade !
Is the spaceship a children of another object?
Is the object Rotated?
Is the script in the "oldest" gameobject (children-parent)?
Give more info.