Easy! move on the -x axis 2d game
rite now I have this script that spawns and moves this objects in random directions sideways up down etc all random direction moving, I want to change the script to make the game objects move in 1 direction which would be forward , I believe this would be -x actually im sure of this, it would be -x on the screen . This is 2d game
so how do I make them move forward automatically on the -x axis?
thanks
using UnityEngine;
using System.Collections.Generic;
// Starting in 2 seconds.// a projectile will be launched every 0.3 seconds
public class sss : MonoBehaviour {
public GameObject prefab;
public Rigidbody2D projectile;
void Start() {
InvokeRepeating("LaunchProjectile", 1.0f, 11.0f);
Destroy (gameObject, 3.5f);
}
void LaunchProjectile () {
Rigidbody2D instance = Instantiate(projectile);
Destroy (gameObject, 3.5f);
instance.velocity = Random.insideUnitSphere * 5;
}
void SpawnItem()
{
// Instantiate the prefab somewhere between -10.0 and 10.0 on the x-z plane
Vector3 position = new Vector3(Random.Range(-3.0f, 4.0f), 0, Random.Range(-3.0f, 3.0f));
Instantiate(prefab, position, Quaternion.identity);
Destroy (gameObject, 3.5f);
}
}
replace Random.insideUnitSphere with -Vector2.right, although I think you mean positive right.
Your answer
Follow this Question
Related Questions
Top Down 2D, facing direction bools 0 Answers
2D Top-Down Shooter Glitch With Camera Focus 0 Answers
I use prefabs in prefabs and when I correct the root prefab of child prefabs, items don't correct. 0 Answers
2D Mobile: How to mask a gameObject with another gameObject (with soft edges) 0 Answers
Walking around a sprite 1 Answer