- Home /
Trace 3D Basketball Shot
I'm making a game in which you shoot basketballs at a hoop in a first-person 3D world. Your player is the standard Unity 1st person player controller. When you shoot, a basketball prefab is instantiated on your player and is pushed up by a force and falls down due to gravity. This means your shots arc.
I want to create a tracer of your potential shot so you can aim better.
I have been working on this for hours by fiddling around and searching the internet, but the tracer I made isn't accurate. I'm guessing the solution is buried in some math I haven't learned yet. I really would appreciate some guidance.
I only know C#
Thanks
Answer by smallbit · May 09, 2015 at 05:37 AM
I had similar problem with my plane game in which i needed to display the aim for bomb drop, bomb was being given the initial velocity with the plane speed. Anyway I did some research and I solve it using the same method they used in angry birds to show the path. What I did was to cast empty gameobjects with the same rigidbody parameters as the bomb and storing their position. Is not the most efficient way but it works. So in your case you could have a pooler of invisible gameobject with same rigidbody as your ball. Than on every update you push a new one of those with the same force and direction as you would push the ball. You have all of this empty objects in the pool so you can easy access theit position. Once ball hits the ground or board or after some time you despawn it. Finally having the positions of each of those you can display something there (i.e. small spheres) or use their positions to draw a line using linerenderers.
//edit one thing you want to make these invisible objects as the parents of your player so when you turn you dont have delay on the tracer.
Also my very first game in unity was a basketball shooting you can find it here https://play.google.com/store/apps/details?id=com.smallbit.basketball&hl=en
I was going to use your method earlier, but I wanted to learn how to code a more fluid solution. I suppose I could use this method, but there are several problems. In my game you hold down the shot button to increase velocity, so the tracer will need to rise. I guess I could just move the points up and down based on my velocity.
Is there anyway to speed up my prefabs arc? If the prefab moved 1000 times the speed of my basketball, the player wouldn't notice the constant adjustments.
the problem is in the fact that you cannot know apriori where the ball will go. Alternatively you can implement your own physic system for throw, i.e. trajctory based on gnerated spline, and some gravity system, in that way displaying the ball trajectory would be simple.
In your problem i cannot think of solution that immidiately updates already spawned objects.
Yep, I think its best to use a prefab. Trail renders seem to look best right now. I'll see how it works in an hour or so.
Trail Renderer looks great, but it doesn't turn correctly when I make it a child of my character. (It bends mid air when I turn, so the line is all zigzaggy) I don't know what I should use. As I said before, if only I could speed up the prefabs flight, the trail renderer would work perfectly.
Well, I'm not getting any responses from anyone. I guess I'll accept your answer soon...
Your answer
Follow this Question
Related Questions
Fps Movement Velocity Decrease 0 Answers
RigidBody.MovePosition seems jerky in movement 0 Answers
Limit & Scaling Translation Rate. 0 Answers
Distribute terrain in zones 3 Answers
Gun not smoothly following player,How to make gun smoothly follow player 1 Answer