Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Hussain4996 · Dec 06, 2014 at 05:24 PM ·

Make ball remain in front of player during player movement

HI am working on football game i have a character name lonhjhon tag name "player" and a ball tag name "ball" i need help regarding how to keep ball in front of player while player is moving forward or right left. (ball control remain in player until he kicks) alt text

ballcontrol logic.jpg (62.4 kB)
Comment
Add comment · Show 3
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 Hussain4996 · Dec 06, 2014 at 02:16 PM 0
Share

I try it by making ball as child to player but it just attached to it from start and it always contains the control, i want to make it if player move toward the ball the ball control will be giving to the that payer until player kicks it, i would be very grateful to you if some one helps me in this

avatar image Hussain4996 · Dec 06, 2014 at 05:38 PM 0
Share

I added rigid body to the ball, player runs fine and if it collide the ball it pushes it 2 or 3 times and than ball left behind,

avatar image Em3rgency · Dec 08, 2014 at 10:04 AM 0
Share

A simple way to do this would be to make a variable, either on the player or on the ball, something like ballInControl. When the player has the ball, set that to true. Then, just check each frame, if the ball is in the players control, set balls position to player position + some offset in front of the player. When the player kicks the ball, set ballInControl to false.

We would need to see the code you have to be able to write a specific answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Muhwu · Dec 08, 2014 at 10:08 AM

If you want the ball to just stick to the player, you can add some sort of joint (and it might behave neatly - for example distance joint). If you want the ball to stay in the position where it touched the player the first time, you can implement OnCollisionEnter(2D?) event so that it stores the relative position of the ball to the player on hit. Then, on every update, you can set the ball position to be the same relative to the player position.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problems with Transform.Find and GameObject.find 1 Answer

new Line in a CustomPropertyDrawer 1 Answer

Simple Timer 2 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