public List <Vector3> GetTrajectoryPoints(Vector3 startPoint, Vector3 endPoint, float time, Color color) { Vector3 initialVelocity = TrajectoryMath.CalculateVelocity(startPoint, endPoint, time); float deltaTime = time / initialVelocity.magnitude; int drawSteps = (int)(initialVelocity.magnitude - 0.5f); Vector3 currentPosition = startPoint; Vector3 previousPosition = currentPosition; Gizmos.color = color; List <Vector3> positions = new List <Vector3> { startPoint }; if (IsParabolicVelocity(initialVelocity)) { for (int i = 0; i < drawSteps; i++) { currentPosition += (initialVelocity * deltaTime) + (0.5f * Physics.gravity * deltaTime * deltaTime); initialVelocity += Physics.gravity * deltaTime; positions.Add(currentPosition); previousPosition = currentPosition; } } positions.Add(endPoint); return(positions); }
public void Throw(string itemName, float reachtime) { GameObject objToThrow = null; if (itemName == "gold") { objToThrow = Instantiate(Gold, ThrowPoint.transform.position, new Quaternion()); } else { foreach (var armor in _hero.Armor) { if (armor.name == itemName) { objToThrow = Instantiate(armor, ThrowPoint.transform.position, new Quaternion()); break; } } } if (!objToThrow) { return; } objToThrow.SetActive(true); objToThrow.AddComponent <Rigidbody>(); var throwable = objToThrow.AddComponent <Throwable>(); throwable.SoundRadius = SoundRadius; throwable.WaveParticuleLifeTime = WaveParticuleLifeTime; throwable.WaveParticuleEmiter = WaveParticuleEmiter; objToThrow.GetComponent <Collider>().enabled = true; Vector3 velocity = TrajectoryMath.CalculateVelocity(objToThrow.GetComponent <Collider>().bounds.center, Target.transform.position, reachtime); var objectInterface = objToThrow.GetComponent(typeof(IPropelBehavior)) as IPropelBehavior; if (objectInterface != null) { objectInterface.React(velocity); } }