Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 JoeAN · Aug 07, 2015 at 08:35 PM · javascriptphysicsball

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

Comment
Add comment · Show 11
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 CaKeMeaT · Aug 07, 2015 at 10:48 PM 0
Share

I think you're going to have to handle the state of following the player(rolling) VS getting kicked (Addforce) with grace.

avatar image getyour411 · Aug 07, 2015 at 11:14 PM 0
Share

As a lifelong player, coach and fan - I love your "solution" I think $$anonymous$$essi has that fix too. Seriously, show your physics code.

avatar image Runalotski · Aug 07, 2015 at 11:36 PM 1
Share

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

avatar image JoeAN · Aug 08, 2015 at 07:41 AM 0
Share

I'm currently not home. But I will post the script when I return after around 9 hours.

avatar image JoeAN · Aug 08, 2015 at 05:01 PM 0
Share

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

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


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