- Home /
Question by
TheHardkaare · May 02, 2014 at 06:38 AM ·
directionmovingwrong
Entity moving along the wrong axis
My asteroids are moving in the wrong direction. When moving, it moves along the blue axis, but it has to move along the green axis. Here's a picture of it: http://i.imgur.com/996BWAY.png
You see, I fixed this problem earlier, but when I integrated the GameController in my game, it started going down the blue axis AGAIN.
This is my code for the movement of the asteroid:
using UnityEngine;
using System.Collections;
public class MoverAsteroid : MonoBehaviour
{
public float speed; //public float tilføjes så værdien kan ændres i selve unity istedet for at være kodebaseret
void Start ()
{
rigidbody.velocity = transform.up * speed; //transform forward er bevægelsen langt z-aksen.
}
}
(Ignore the danish notes) The value "speed" is set to -0.3 in Unity for testing reasons.
And this is the code for my GameController:
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour
{
public GameObject hazard;
public Vector3 spawnValues;
void Start ()
{
SpawnWaves ();
}
void SpawnWaves ()
{
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x,spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
}
}
I believe these two are the only relevant codes for this, otherwise please let me know.
It all works perfectly just if I put in my asteroid prefab, it just doesn't spawn randomly.
As stated, I'm not sure if this is all sufficient, but let me know.
Comment