- Home /
Launch arc with physics/rigidbody problem and on Unity's internal code
All the tutorials I've seen on this require you to use trajectory formulas (E.g. https://www.youtube.com/watch?v=iLlWirdxass&t=1353s) but that has it's own problems. Now I have to find the angle and velocity. I use Addforce with forcemode.impulse though, so I have to convert that to velocity somehow. And as far as i can see there is no easy way to find the angle (I tried vector.Angle, but that only gives between 0-180).
What I'm thinking is, doesn't Unity already have all the formulas built into the engine? When I use Addforce with forcemode: impulse, it has to calculate the trajectory of my rigidbody anyway, so why can't i access that? I tried looking in the documentation and in Unity's engine, but I can't find anything. Does anyone here know?
You can still give a try to this for projectile trajectory implementation.
Answer by Captain_Pineapple · Jan 29, 2019 at 09:23 AM
Hey there,
as far as i know the short answers is sadly no.
Why: Unity does NOT calculate trajectories up front, at least not the complete trajectory. This has multiple reasons in which i do not want to dive too deeply. (If you want to learn more about this then look into system theory for machanics and dynamic systems) Basically what unity does is iterate all the physics in multiple step but just for the next frame. So there is some slight prediction there, but just for 1 frame in the future to check for collisions. Any more calculation will be just useless since the whole setup might change due to scripts. (e.g. you reset some positions, add new objects...) And useless calculations equals to bad performance here. So yes in some way the equations exist somewhere deep in the physics system but are probably not accessible to you. If you really only want to create a simple parabola for a certain object with given mass and constant gravity then you should rather just calculate this on your own.
If you need help with this feel free to ask, it's not that difficult and one can learn quite a lot when trying this :) You can also look at this question for reference. This question was about making an object always hit the same point with disregard for the launch angle and mass. So here we had to calculate a fitting "gravity". When you have the formula for whatever you need then creating a line from it is the easy part.
No answer for almost 2 months and then suddenly there's 2. Anyway, thank you :) I'll have to check out what you and the other guy linked before I can say for sure whether I need help or if it's too much of a hastle XD Won't have time until the weekedn for that though ^^ But thanks for the explanation. that makes sense and I didn't think of that ^.^ Does your reference explain how to deal with bounce as well? Like calculating the angle a ball will have when bouncing off a wall?
Hey,
yeah i did not look at the time of creation :D it jsut popped up as "new" since there was a new comment on this.
Well the complexity of your issue depends heavily on your setup. Is there gravity involved or not? if not then this is a rather easy issue. With gravity you have to look up some calculations on how objects behave when they are thrown vertically/horizontally/angled. (which in the end is basically the same with different start conditions). It gets even trickier if you want to include spin/angular momentum into your calculation. Let me know a bit more about what you want to calculate/animate/predict and perhaps we can sort out the math needed.
Okay... So what I want to do is to predict a balls motion over distance in 2d space with gravity being a factor. I want to make a indicator, you see, so the player will be able to see the curve the ball will take, I think the biggest problem comes when walls are involved. I use physics.impulse to send the ball flying with force, and I have physics material on the walls (0.4 friction and 0.3 bounciness for now). I'm not big on math except if it's vector math which i adore XD So will probably need a lot of help if you're up for it ^^ if not then that's fine too