- Home /
I am having a problem trying to simulate football(soccer) physics
I am trying to make a football game and there's that issue that's bothering me:
●Problem: The ball just keeps rolling on the floor no matter how hight the friction value is and it isn't practical for dribbling.
●Solution: I applied a script (js) to the ball stating that its coordinates are very close to the player ( the player is a Transform
variable ). That way the ball would follow the player wherever he goes.
●Other problem: I applied another script to the ball: when the gamer presses the X key Input.GetKeyDown(KeyCode.X)
, a force is applied to the ball GetComponent.<Rigidbody>().AddForce(Vector3.forward*shotPower);
but the force couldn't be applied because an other script is telling the ball to follow the player's coordinates
I want the ball not to roll forever on the floor but on the other end, I don't want the ball to follow a script dictating its coordinates.
I hope my question is clear. Hope to hear answers soon Thank you for your time, Joe :-)
PS: I only know Javascript
I think you're going to have to handle the state of following the player(rolling) VS getting kicked (Addforce) with grace.
As a lifelong player, coach and fan - I love your "solution" I think $$anonymous$$essi has that fix too. Seriously, show your physics code.
To stop the ball going forever you need to add drag. you do this on the rigid body it has angular drag to stop it rotating and linear drag to stop it moving. setting these values high will stop the ball faster
Friction stop it from slipping.
if you psot the code of how the player keeps the ball we can help with how to switch in and out of it
I'm currently not home. But I will post the script when I return after around 9 hours.
The script that lets the ball follow the player: #pragma strict
var myDribller:Transform;
function Start () {
}
function Update ()
{
transform.position.x = myDribller.position.x;
transform.position.z = myDribller.position.z + .3;
}
The script that applies a force to the ball: #pragma strict
var shotPower:int = 100;
var myShooter:Transform;
function Start ()
{
}
function Update ()
{
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.X))
{
GetComponent.<Rigidbody>().AddForce(Vector3.forward*shotPower);
}
}
Notice that in the second script the ball is always pushed in the same direction(Vector3.forward). I want the ball to be pushed in the direction the player is looking at. That's another problem that I will try to solve later.
Runalotski I added the drag value as you told me to and I noticed that the ball stopped moving all the time, howerver it's still hard to drible without a script
Answer by MaximuSR · Oct 26, 2015 at 06:55 PM
There are many examples of soccer games made in unity. You can check Soccer Physics as example of one.
,There are already many examples of soccer games made in unity. You can check Soccer Physics for more info.
Your answer
![](https://koobas.hobune.stream/wayback/20220611234839im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a ball jump on plane collision 1 Answer
How do I switch from Character player to Airship Vehicle using triggers? 0 Answers
How do I "remove/disable" collision? 3 Answers
Player-controlled rigidbody ball sometimes slowing down for no reason 0 Answers
How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers