- Home /
a way to predict players position to be able to be hit by projectiles
hi, I'm making a Boss AI that I need is a way the Boss AI to trow projectile and predict its future position base on the speed of the player. the player either on land or air vehicle. the projectile has a constant speed, a rigidbody, and can easily be seen by the player want I want is that the player has a chance to dodge the projectile. don't worry about the speed constant I already have that one just the prediction is what I need.
this is the player controls just in case you need it
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpeedupSkill : MonoBehaviour { protected SpeedButton SpeedButton; //looking for script leftbutton public float cooldownTime = 7; private float nextFireTime = 0; private double nextFireTime2 =0; private double nextFireTime3 = 0; public double cooldownTimeleft = 0.2; public double cooldownTimeright = 0.2; public float maxSpeed = 100f; protected Leftbutton LeftButton; //looking for script left buttton protected Rigthbutton RigthButton; //looking for script right button
public int damage = 50;
// Use this for initialization
void Start()
{
SpeedButton = FindObjectOfType<SpeedButton>();
LeftButton = FindObjectOfType<Leftbutton>();
RigthButton = FindObjectOfType<Rigthbutton>();
}
// Update is called once per frame
void Update()
{
var rigidbody = GetComponent<Rigidbody>();
if (SpeedButton.Pressed && Time.time > nextFireTime)
{
rigidbody.velocity += Vector3.forward * 100f;
nextFireTime = Time.time + cooldownTime;
GetComponent<Renderer>().material.color = Color.red;
}
if (LeftButton.Pressed && Time.time > nextFireTime2)
{
rigidbody.velocity += Vector3.right*1.0f ;
nextFireTime2 = Time.time + cooldownTimeleft;
Quaternion.LookRotation(Vector3.forward);
}
if (RigthButton.Pressed && Time.time >nextFireTime3)
{
rigidbody.velocity += Vector3.left*1.0f;
nextFireTime3 = Time.time + cooldownTimeright;
Quaternion.LookRotation(Vector3.forward);
}
if (rigidbody.velocity.magnitude < maxSpeed)
rigidbody.velocity += Vector3.forward*30.0f;
else
rigidbody.velocity += Vector3.forward * 0.0f;
if (rigidbody.velocity.magnitude < 29.9f)
rigidbody.velocity += Vector3.forward * 1.0f;
var grounded = Physics.Raycast(transform.position + Vector3.up * 0.05f, Vector3.down, 2f);
Debug.DrawRay(transform.position + Vector3.up * 0.05f, Vector3.down, Color.red, 0.1f);
if (!grounded)
rigidbody.velocity -= Vector3.down * -2.0f;
}
}
edit: the game is 3d