Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GameMadeByGamers · Oct 09, 2020 at 12:33 AM · vector3projectiletrajectoryballistic

Interpolated Projectile in vertical arc and horizontal (blendable)

My goal is to interpolate a projectile position through 2 arc (one vertical and 2 other horizontal) being able to blend them together to give particular angle of approach. But i dont understand how to integrate the horizontal axis since the arc is in both the x and z axis depending of the target position. I try with Bezier but i was stuck with inconsistent speed.

         private Vector3 CalculateNextPosition()
         {
             //Y Arc
             Vector3 yZeroStartPos = new Vector3(startPosition.x, 0, startPosition.z);
             Vector3 yZeroDestination = new Vector3(destination.x, 0, destination.z);
             //Move straight forward
             Vector3 nextPosStraigth = Vector3.MoveTowards(new Vector3(transform.position.x, 0, 
             transform.position.z), yZeroDestination, speed * Time.deltaTime);
             float dist = Vector3.Distance(yZeroStartPos, yZeroDestination);
             //Add in the arcs
             float t = (nextPosStraigth - yZeroStartPos).magnitude / dist;
             float baseY = Mathf.Lerp(startPosition.y, destination.y, t);
             float arcY = arcYAxisHeight * (nextPosStraigth - yZeroStartPos).magnitude *
             (nextPosStraigth - yZeroDestination).magnitude / (0.25f * dist * dist);
 
             return nextPosStraigth + new Vector3(0, baseY + arcY, 0);
         }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eno-Khaon · Oct 09, 2020 at 01:00 AM

Your singular X-axis in a typical trajectory calculation is the combination of both the X and Z axes into a single value.

 Vector3 flattenedAxes = new Vector3(xDistance, 0f, zDistance);
 float combinedAxis = flattenedAxes.magnitude;


I took things a bit further with trajectory calculations in an older answer. It's focused around Rigidbody physics calculations specifically (and leaves the rest of the process up to that), though I also included (late in a comment chain) a basic trajectory prediction scheme in this other answer.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GameMadeByGamers · Oct 09, 2020 at 01:34 AM 0
Share

Thanks for the answer! I'm suppose to do the Y arc like i did and the horizontal separately to addition them to the final vector? I have difficulty to see how i can apply the arc on the "good" x or z axis.

avatar image Eno-Khaon GameMadeByGamers · Oct 09, 2020 at 02:49 AM 0
Share

(I converted your answer to a comment for you. Keep in $$anonymous$$d to "Add comment" to an answer, rather than using the prompt to add a new answer in this situation)

After you've made your calculations with the horizontal axis separated out, you can recombine it into the X/Z axes by multiplying by their normalized value:

 // Simplified a bit
 
 // First, the X/Z values from the to-from vector
 Vector3 horizontalAxis = new Vector3(xDistance, 0f, zDistance);
 
 // Normalize for a length of 1 between both axes
 Vector3 rebuiltAxis = horizontalAxis.normalized;
 
 // Extend to intended length of horizontal axis (float)
 // in trajectory calculation
 rebuiltAxis *= horizontalLength;
 
 // Re-insert Y-axis
 rebuiltAxis.y = yLength;
avatar image GameMadeByGamers · Oct 09, 2020 at 03:30 PM 0
Share

Ok so i redo the same thing with the x and y and multiplied the result with the rebuiltAxis ? like (BaseX + ArcX) * RebuildAxis.x

avatar image Eno-Khaon GameMadeByGamers · Oct 09, 2020 at 09:18 PM 0
Share

Ahh, whoops, looks like I misread your original question a bit. Depending on your intent for a "horizontal" arc in your trajectory, it should effectively be as straightforward as changing the direction of gravity in your calculations. What that would mean, however, is that you can't depend solely on replacing a single axis at a time.

Using my first link in my answer as an example, you would want to separate out the horizontal and vertical axes based on your intended "Gravity" (e.g. where the baseline gravity is Vector3(0, -9.81, 0) you would factor in wind (or a similar element) to that vector, then apply that modification as a velocity change to the object in flight). From there, that example would aim to hit the target based on an applied "gravity" (which, in this case would be gravity + wind/etc.).

Then, using my second link as an example, you would iterate from the starting position and velocity, using the (gravity + wind/etc.) vector based on how many time steps forward you're looking to go.

That doesn't mean you have to iterate through in that manner, however. What it does provide is an accurate recreation of the path it would take using PhysX in Unity. If you want the close-enough outcome based on real-life predictive physics, however, you can still use the separated vertical/horizontal axes (since the final result in this case would still be a 2-D arc). Your position at any given time would look about like this:

 float h; // The current horizontal position (linear)
 float v; // The current vertical position (parabolic)
 Vector3 hA; // the horizontal "Axis" perpendicular to "Gravity"
 Vector3 vA; // the vertical "Axis" (normalized, inverted "Gravity")
 Vector3 currentPosition = hA * h + vA * v;
avatar image GameMadeByGamers · Oct 09, 2020 at 10:21 PM 0
Share

No problem thanks for your help, it's me that was to vague. I reformulate my initial question. $$anonymous$$y goal is to interpolate a projectile position through 2 arc (one vertical and 2 other horizontal) being able to blend them together to give particular angle of approach.

Am able to do the interpolation of the individual arc but im stuck with the horizontal one (XZ) since the interpolation is and world position and not relative to the forward of the "shooter".

I would like to arc on the z axis relative to the shooter (perpendicular)

avatar image Eno-Khaon GameMadeByGamers · Oct 10, 2020 at 03:01 AM 0
Share

I guess at this point, it kinda boils down to what you're looking for in the horizontal axis.

If your goal is a fixed influence on velocity (such as wind), then the trajectory is still 2-Dimensional, but the axes would need to be clearly defined. The solution for that is what I've been describing so far, but if you need any more information, just let me know.

On the other hand, if your goal is a more free-form approach (such as using Bezier curves), then you may want to look at some information on traversing a Bezier curve at a fixed speed. This approach would result in the vertical axis of the trajectory being back to Y-axis only (as a general rule), and the horizontal axis would instead become the current position along a 2-D path (Where the position along the curve is, itself, a 1-Dimensional parameter).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Find trajectory angle needed to hit an object 0 Answers

Increase velocity without changing trajectory 1 Answer

Projectile trajectory 1 Answer

how to draw trajectory of rocket for faux gravity in unity???? 0 Answers

How will I draw a curve that represents the trajectory of a projectile? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges