c# - Adding additional vertical velocity in projectile motion Unity3D -


I have mine and my enemy to throw at some height above the ground (which is moving from right to left and shooting Is the point on the horizontal axis) on the ground. The projectile speed is that I shoot straight at the angle facing the enemy, but I want the projectile to go upwards and then shoot the enemy.

I have the snapshot attached below:

Here is my code:

  using UnityGen; Using System.Collections; Public class bullet: Monobehavier {public conversion goal; Private mytransform conversion; Public Game Object bulletproofab; Public game object enemy motions; Private gamingem e; Public float firing angle = 20; Public float gravity = 9.8 f; Zero awake () {mytransform = transform; } // Use it for initial zero start () {mytransform.LookAt (target); Start korenine (project ()); //Follow(); } IEnumerator project () returns yields new WaitForSeconds (0.25f); Float target_Distance = Vector3.Distance (mytransform.position * target_Distance, target.position); // Calculate the velocity required to throw an object at a specific angle Flat projectileity = liquid distance / (Math Sin (2 * lane distance * math dg2rd) / gravity); // Velocity float Vx = Extract XY Electrical of Mathf.Sqrt (Projector_Visocity) * Mathf.Cos (target_Distance * Mathf.Deg2Rad); Float Vy = Mathf.Sqrt (Projectel_Vilocity) * Methsin (1 / target_Distance * Mathf.Deg2Rad); // Calculate the flight time Float FlightDirect = Target System / VX; // Rotate projectile to face goals Mytransform.rotation = Quaternion.LookRotation (target.position - mytransform.position); Float elapse_time = 0; While (elapse_time & lt; flightDuration) {mytransform.Translate (0, (V - (gravity * elapse_time)) * Time daltamime, Vx * Time.deltaTime); Elapse_time + = Time.deltaTime; Yield returns; }} Snapshot of how it was done with the given code:  

image here Enter details

  How do I like to:  

To calculate the movement in your code Instead, consider using a harsh person on your projectile, then at the time of firing, relative to the initial trajectory (ie direction The gun is facing the barrel) and gravity also affects your bullet.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -