Giving objects a cruve

Does anyone know where I can find resources for how to calculate a curve? I’m trying to instantiate an object then have it choose a random angle, random 360 degree direction, and random speed to send it off in a direction. Similar to if you were firing an object out of a cannon but without the cannon being there. I want to use x,y,z positions instead of physics or rigidbody force as well.

Edit: Yes I spelled curve wrong lol

https://www.assetstore.unity3d.com/#/content/8358

var bullet : GameObject;

function Start()
{
    var x = Random.Range(180,-180);
    var y = same as that ^^^;
    var z = same as this ^^^;

    Instantiate(bullet, transform.position, Vector3(x,y,z));
}

Should Work, I havent tried it.

Not looking to buy anything. I would like to know how to do this sort of math.

I’m guessing that is just for the rotation though? Doesn’t explain how to give it a curve when fired.

so u want physics? on the bullet just apply - Component>Physics>Constant Force

I tested it out but am not sure if that is what I need. I drew up a simple image of what I’m trying to do.

http://i.imgur.com/yNqVGlZ.jpg

So u are asking for a bullet drop physics? add Component>Physics>Rigidbody

Is there anyway to program it with a equation instead of using physics?

oh u silly :P, u dont need enstein to reinvent gravity equations for you, just use this:

var drop = 1;

function Start()
{
    Physics.gravity = Vector3(0, drop, 0);
}

Hmmm o,o I guess I would just apply force to the object and it will calculate all that out. I shall give it a try!

constant force and this script are same things, except that Constant Force is a unity3d component meaning its better than mine :slight_smile:

You should use a polynomial equition to do this. The code below I used to draw a curve with small plane particles. You can replace the part in the update function with your own equation, which will probably be a parabola, rather than the one I used. Also, yours might not be in the update function, except if you want to change the angle or curve in realtime. But, please, this is only if YOU want to determine the path yourself.

Here you go, hope this helps!

using UnityEngine;
using System.Collections;
using System.Collections.Generic;



public class lazer_beam : MonoBehaviour {

    public List<Vector3> points = new List<Vector3>();

    public List<GameObject> planes = new List<GameObject>();

    float const_a;
    float const_b;
    float const_c;

	void Start () 
    {
        LoadPlanes();
        SetupPoints();
        StartCoroutine("ChangeLazer");
	}

    void LoadPlanes()
    {
        for (int i = 0; i < 100; i++)
        {
            GameObject go = (GameObject)Instantiate(Resources.Load("prefabs/lazer_particle"));
            planes.Add(go);
            go.transform.localEulerAngles = transform.localEulerAngles;
            go.transform.localScale = new Vector3(0.008f, 1, 0.008f);
            go.layer = 9;
            //Destroy(go.GetComponent<MeshCollider>());
            go.transform.parent = transform;
        }
    }

    void SetupPoints()
    {
        for (int i = 0; i < 100; i++)
        {
            points.Add(new Vector3(transform.position.x + (i * 0.02f), transform.position.y, transform.position.z));
            planes[i].transform.position = points[i];
        }
    }

    void Update() 
    {
        float x = 0;
        float y = 0;

        for (int i = 0; i < 100; i++)
        {
            x = transform.position.x + (i * 0.01f) - 0.5f;
            y = (x * x * x * x * const_a) - (x * x * x * const_b) + 0.5f;
            Vector3 temp = new Vector3(x, y, transform.position.z);
            planes[i].transform.position = temp;
        }
	
}

    IEnumerator ChangeLazer()
    {
        yield return new WaitForSeconds(1);
        const_a = Random.Range(-10, 10);
        const_b = Random.Range(-10, 10);
        StartCoroutine("ChangeLazer");
    }


}

Thank you! This was the kind of code I was hoping someone would post. I’m trying to make patterns like bullet hell games so would this be the start of that kinda?

Explain a bit more what yo umean with “bullet hell games” and the patterns, then I can tell

That’s what most people call them. They are the 2d top down games where you control a plane usually and avoid large amounts of bullets. Everytime the bullets are fired they usually follow a certain pattern.

https://www.youtube.com/watch?v=kprTutpv8qE

The example you gave, seems to me like those bullets are actually moving straing and you get the illusion that they are moving at a curve when they are spawned fast in succsession. So all they are doing there is to change the x position ( and y obviously) of the bullet, based on the x_speed of the player plain. Thinking about my script again, creating an ground-to-ground trajectory using a parabola might give you problems with interpolating smoothly between the points on the curve. And that is a dark art I must still do at some stage for one of my projects:)

for all curves and other. A lifesaver!