- Home /
Object following the path
Basically my question is in this image.
To be clearer I want the object,which is a ball in my case, to follow one of the paths after checking rec attribute.
If rec is greater than 80 it follows path one (green one in the picture), if rec is lower than 80 and greater than 60 it follows yellow path and if it's lower than 60 the dark red path.
Edit: Here's my current working file so you can see my current problem. Hit the ball with A with first player, and X with second player.
Edit 2: There was a problem with my upload, I accidentaly posted wrong link. Now it's OK
Sorry, but i don't see a question here... more a "write-my-script-request" where Unity Answers is the wrong place.
If you search for people that want to work with you on your project go to the Unity Forums
If you have a specific question about Unity feel free to ask if you have trouble with the API or the syntax, but ask one question at a time. Be specific and include what you've done so far.
You might have a look at the FAQs
Answer by RetepTrun · Oct 30, 2011 at 01:35 AM
Perhaps understand this script and add some if() to it
http://www.unifycommunity.com/wiki/index.php?title=Trajectory_Simulation
Answer by Fabkins · Oct 30, 2011 at 10:30 AM
Judging from your picture it looks like you are creating a physics based ball game. The above link from RetepTrun seems pretty helpful.
I must admit your question is little difficult to follow but taking a stab at what I think you want to do. You may want:
Use the built in physics engine
Fire the ball at a given tradjectory dependent on the position of the rect (bat?).
So lower the bat, steeper the angle vs vice versa (think thats how volley ball works)
I suggest this because we not really sure what you mean by follow a path. How did you define this "path".
PS I think it is unfortunate that you've been downvoted as it looks like you are putting genuine effort into this.
i thought of lowering the bat and vice versa, but i was wondering is it possible to somehow create a fixed path for the ball to follow after colliding with player?
Why would you do that? Doesn't it make the game completely predeter$$anonymous$$ed?
maybe, but i want to make the simple simulation first, and then input more and more paths depending on player attributes, their position on court, height, and other(add 10 or 15 more paths to these ones on picture). That way it would not be completely predeter$$anonymous$$ed.
@Scafciger, you are aware that you can use Unity's own physics engine?
I think to create a path is actually difficult and to make it follow it doubly so.
Create a Sphere for a ball. Then add a Rigidbody. $$anonymous$$ake the material bouncy. Thats the ball. Then just project it in a direction , the game will do the rest!
Let Unity to do the work? No?
i've tried doing it with rigidbody , but directons the ball goes after collision are not like what was lookin for, that's why i wanted the ball to follow the path.
Answer by Fabkins · Oct 30, 2011 at 04:02 PM
How are you going to define this path? You going to have to create a parabollic curve that is a physics representation of what should happen to the ball. So how are you going to create this path yet alone follow it?
I can understand and I would have expected you not to want the standard behaviour on collision with a players hands. So on collision with the player you can set the trajectory to where you want it to go.
You have two choices really in all of this.
Use the existing physics engine, tweaking it to your needs or create a new one. Seems for what you are trying to do I would use the existing one.