• 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 greatUnityGamer · Feb 21, 2015 at 04:24 PM · physicsball

How do you Throw a Basketball towards a basket or Roll/kick it?

If my character just runs through it it should be kicked or rolled along the ground. If my character picks it up then throws it , it should start a projectile path but shouldn't land perfectly in the hoop always.

so how do you roll a ball along the ground? i would need to make the ball rigidbody and apply Rotation? But how?

How about kicking it?

And how about shooting it as in basketball. Kicking it and shooting it should be different, kicking is kind of a projectile but it has snap power to it. I dont know how to do it.

thank you

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by skylem · Feb 21, 2015 at 04:51 PM

if u were rolling a rigidbody you would want to apply torque or relativetorque

rigidbody.AddTorque(Vector3.forward * 500);

the way in which u would kick the ball would depend on how u are animating the character, you could add a collider to the Foot joint of your player character if it is a biped humanoid, you could also add this collider to a different layer so that it would only collider with the layer the ball is on.

alternatively u could use a raycast to determine if the foot makes contact while playing the kick animation, and there is also lerping u can use a lerp to move an object from A to B over a set amount of frames. its hard to provide a detailed answer when you haven't provided information on how your character works, examples of raycast and lerp below. this raycast uses the layer "Floor" to determine wether our Ray makes contact with the ground contact respresents the point the raycast meets an object u can also use this to grab a transform and tag like so

 if(contact.transform.tag == "Floor") {
  do stuff here cause the raycast hit the floor
 }

 RaycastHit contact;
 floorMask = LayerMask.GetMask ("Floor");
 
 if(Physics.Raycast (transform.forward, out contact, 0.5f, floorMask)) {

}

 transform.position = Vector3.Lerp(transform.position, toB.position, 0.01f);
 
 u could use a 
 
 Random.Value to affect the the position of toB
 Random.Value returns a float ranging anywhere from 0 - 1.0
 using in a multiplication, for 50/50 chance.
 float RandomAmount = Random.Value;
 
 if(RandomAmount  >= 0.5f) {
 
 }
 else if(RandomAmount  < 0.5f) {
 
 }




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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get a free moving ball. 1 Answer

I am having a problem trying to simulate football(soccer) physics 2 Answers

How could I make a bouncy object move mostly along the Z axis? 1 Answer

Need help with the physics and angles of gerbils in a plastic ball.. 2 Answers

How to predict where the ball will fall? 4 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