Launching an Enemy

EDIT: Hi Guys! I’m new here, but I’m trying to do something I think is really simple, but can’t get it for the life of me. I’m trying to “launch” cows across the screen as if there is a hurricane blowing them in the wind (complete with Quaternion). I got them to instantiate perfectly, transform.Translate isn’t working the way I need. Please see my code below:

using UnityEngine;
using System.Collections;

public class CowLauncher : MonoBehaviour
{

    public float delay = 0.1f;
    public GameObject cow;
    public Vector2 launchSpeed;
    public int cowSpeed;
    private bool spawnedTrue;

    void Start ()
    {
        InvokeRepeating("Spawn", delay, delay);
        spawnedTrue = false;
    }

    void Spawn ()
    {
        Instantiate(cow, new Vector2(3.59f, Random.Range(-0.5f, 1)), Quaternion.identity);
        spawnedTrue = true;
    } 

    void FixedUpdate ()
    {
        if (spawnedTrue)
        {
            transform.Translate(cowSpeed * Time.deltaTime, 0f, 0f);
        }

    }
}

This just causes my empty game object that it’s attached to to move, and not the cows :stuck_out_tongue: Also, it doesn’t make the cows spin? It doesn’t spin with the Quaternion.identity because it’s 2D? Any help would be greatly appreciated!

When you reference transform.position it gets the transform of the gameobject that the script is attached to, so you’re rotating the Cow Launcher itself.

There are ways you can rotate the cow from this script but personally I’d make a cow script and attach it to the prefab gameobject then move the rotating code to the cow script and that should work!

Let me know if you have problems :slight_smile: