Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ekta-Mehta-D · Dec 11, 2013 at 07:41 AM · physicsmathprojectile

Calculate Height of Trajectory : Unity3d

hello everyone ,

I have done trajectory motion and its working perfectly..

For calculating velocity i have written code like this :

 function GetTrajectoryVelocity( startingPosition : Vector3,  targetPosition : Vector3,  lob : float ,  gravity : Vector3) : Vector3
     {
         var physicsTimestep : float = Time.fixedDeltaTime;
         var timestepsPerSecond : float = Mathf.Ceil(1f/physicsTimestep);
         
         var n : float = lob * timestepsPerSecond;
         var a : Vector3 = physicsTimestep * physicsTimestep * Physics.gravity;
         var p : Vector3 = targetPosition;
         var s : Vector3 = startingPosition;
         
         var velocity : Vector3 = (s + (((n * n + n) * a) / 2f) - p) * -1 / n;
         velocity /= physicsTimestep;
         return velocity;
     }

The equation for calculating max height is here : Maximum Height

But i to calculate height using this equation ? I am having velocity , angle .

So my problem is how do i make equation in code?

Thanks for your help till now..

Comment
Add comment · Show 1
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 robhuhn · Dec 11, 2013 at 08:10 AM 1
Share

Why don't you use the equation h = pow(v sin(θ), 2) / 2g* provided on the site you linked?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by MrVerdoux · Dec 11, 2013 at 08:12 AM

First of all, I don´t think you should recreate the whole physics system, Unity has an amazing built-in physics system, and it´s much more efficient than anything you can come up to.

But, anyway, your question has an answer. I guess you must have an initial velocity, apart form an initial position. You can calculate the angle from that initial velocity:

 var initialVelocity : Vector3; 
 var angle : float;

 function Start () {
     initialVelocity = new Vector3(1,1,1);
     angle = Vector3.Angle(new Vector3(initialVelocity.x,0,initialVelocity.z), initialVelocity);
 }

edit: and of course, form that point use the equation pointed by robhuhn, I assumed your problem was with finding the angle.

Comment
Add comment · 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

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

18 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

Related Questions

Projectile motion of an arrow after applying force 3 Answers

shoot a cannon ball cannot run !! 0 Answers

Projectile trajectory velocity and angle instead of force with a rigidbody 2 Answers

Calculating trajectory of elliptical orbit? 2 Answers

Vector3 and power 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