Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 OneCode-Official · Oct 13, 2019 at 10:52 AM · physicsvelocitytrajectoryforcesthrowing

Calculate a trajectory in all possible directions (2D).

I want to draw a trajectory from a Ball which the player can launch in all directions(up,down,right,left). For example the force could be (1,2) , (-3,4) and so on. I was searching for Formulars to calculate some points which I can draw a trajectory with in the web, but I was not able to find anything.

In the following Image you can see what I try to archive. The red ball in the middle is the player. By dragging the mouse a Force is being calculate. The Force can let the ball fly in all directions.

What Im trying to archive is to draw the "fly line".

alt text

Can someone explain me what I have to do please?

tranjectory.png (15.0 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by lgarczyn · Oct 13, 2019 at 11:35 PM

The other answer has an issue, it's that unity doesn't actually uses parabolas to simulate trajectories, but an approximation of them. If you use parabolas, the projectiles won't match your predictions, and you'll accumulate errors with time. This will get worse with a lower physics tickrate.

What you want is something like this:

 Vector3 currentPos = startPosition;
 Vector3 prevPos = currentPosition;
 Vector3 currentVelocity = startVelocity;

 for (int i = 0; i < stepCount; i++)
 {
     currentPos += currentVelocity * Time.fixedDeltaTime;
     currentVelocity  += Physics.gravity * Time.fixedDeltaTime;

     //Replace by a TrailRenderer or LineRenderer
     Debug.DrawLine(prevPos, currentPos, Color.Red, 1f);
     prevPos = currentPos;
 }

This only works with a drag factor of 0, but the unity drag approximation can also be easily copied.

Comment
Add comment · Show 4 · 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 OneCode-Official · Oct 14, 2019 at 11:18 AM 0
Share

Thank you for the answer. Can you tell me which drag factor I need to set to 0. At the moment Unity is drawing a staright line.

avatar image lgarczyn OneCode-Official · Oct 14, 2019 at 06:26 PM 0
Share

Is your Physics.Gravity set to anything? $$anonymous$$aybe StartVelocity is too big. $$anonymous$$aybe stepCount is too low, it should be around a 100 to 300.


The drag factor is 0 be default I think, but you can change it inside the Physic$$anonymous$$aterial of your projectile. It's probably not the issue here.

avatar image OneCode-Official lgarczyn · Oct 15, 2019 at 11:01 AM 1
Share

I don't know what I done wrong yesterday but it worked out perfectly today. Thank you very much :D.

Show more comments
avatar image
0

Answer by RadonRaph · Oct 13, 2019 at 01:22 PM

Hello @OneCode-Official, your question is not very clear. If your object is in (0,0) and you apply a force (1, 2) m/s² it will be at (1,2) in 1 ms, at (2,4) in 2 ms etc If you have gravity you need to substract 9.81 at Y axis so same exemple (0,0) + (1,2) = 1ms (1,-7.81), 2ms (2, -17,62) etc You use https://en.wikipedia.org/wiki/Classical_mechanics from Newton :) Hope that help. Raph

Comment
Add comment · Show 4 · 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 OneCode-Official · Oct 13, 2019 at 02:48 PM 0
Share

Thank you for your answer, I think this could help me a lot. Sorry for not being very clear but my english is not that good.

avatar image OneCode-Official · Oct 13, 2019 at 03:21 PM 0
Share

I tried it out and it did not worked out for me. I updatet my question so you can understand better what I am trying to do. Nevertheless thank you very much.

avatar image RadonRaph OneCode-Official · Oct 13, 2019 at 08:05 PM 0
Share

Oh ok thats more clear. First step you need to get drag input:

     Vector2 mouseDrag;
     
     Vector2 BeginDrag;
     
     void On$$anonymous$$ouseDown(){
          BeginDrag = Input.$$anonymous$$ousePosition;
     }
     
     void On$$anonymous$$ouseDrag(){
          mouseDrag = Input.$$anonymous$$ousePosition-BeginDrag;
     }
 
 

With this you will get the mouse offset. If you inverse the vector you will get the direction of your ball and the magnitude of the vector is the "force". Then i wonder how you can draw that x) il will make my research :)

avatar image OneCode-Official RadonRaph · Oct 14, 2019 at 11:22 AM 0
Share

Thank you. I already managed to calculate the velocity of the ball. Drawing the path is the only problem I have at the moment

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

187 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 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

How to make an orbital movement as smoothly as possible? 0 Answers

strange unrealisticly physic problems about velocity/gravity acceleration 2 Answers

Drawn trajectory different than real trajectory 2 Answers

Calculate velocity to set to reach a target point on a plane considering the drag. 0 Answers

SImply yet tricky question about RELATIVE VELOCITIES... 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