
Now how the projectiles move is the star in this picture has a component called Gravity Source on it, and it supplies the force calculations:
using UnityEngine;
using System.Collections;
public class GravitySource : MonoBehaviour
{
public Vector3 ForceAtPoint(Vector3 xyz)
{
var newForce = transform.position - xyz;
if (newForce.sqrMagnitude > 0.0f)
{
newForce = (newForce / newForce.sqrMagnitude) * 5000.0f;
}
return newForce;
}
}
and the missiles & player have a Gravity Receiver, the missiles having a 10x multiplier and players 1x
using UnityEngine;
using System.Collections;
public class GravityReciever : MonoBehaviour {
public float gravityMultiplier = 1.0f;
public GravitySource gravitySource;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate () {
rb.AddForce(gravitySource.ForceAtPoint(transform.position) * Time.fixedDeltaTime * gravityMultiplier, ForceMode.Acceleration);
}
}
Now my question is, how do I calculate where a projectile is going so I can have my AI make decent shots as well as dodging incoming fire?https://dl.dropboxusercontent.com/u/168938/Games/Space%20Melee/OrbitProjectileExample.zip (a copy of the physics code with all the assets removed to play around with/make examples)