• 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
1
Question by White · Jul 02, 2012 at 08:48 PM · force

How do I apply realistic force for an air-hockey game?

I've been trying for a while to develop such a game, but the game play is so annoying because of the force that I apply. Here's my code :

 #pragma strict

var bounceForce : float = 10;

function OnCollisionEnter(hit : Collision)

{

if (hit.collider.gameObject.tag == "Sphere"){

print("Collision");

 hit.rigidbody.AddForce(hit.contacts[0].normal * bounceForce, ForceMode.Impulse);

} }

The puck ( I think that is how you call it, I'm not English sorry) has the tag "Sphere". Can anybody give me some hints to use the force properly? Thank you anticipated and if needed, I will make a video showing my problem.

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
Best Answer

Answer by khellstr · Jul 03, 2012 at 01:21 PM

Problem could be that AddForce adds force to center of game object(puck), but actually (in real life) force is added to collision point.

check this out: Rigidbody.AddForceAtPosition

Comment
Add comment · Show 3 · 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
avatar image White · Jul 03, 2012 at 03:56 PM 0
Share

Hello and thank you for your answer. The force is added to the collision point(hit.contacts[0].normal) but my real issue is that when I send the puck directly from one paddle to another it simply stops and it doesn't deflect at all, like it should. $$anonymous$$y problem is that when the puck and the second paddle collide, it cancels the force( the puck comes with a force of 10 and the paddle applies a force of 10, so the resultant force equals 0). I really hope that somebody understands what I say and helps me. :)

avatar image khellstr · Jul 03, 2012 at 06:48 PM 0
Share

The force is added to the collision point AddForce(hit.contacts[0].normal ...

At this case "hit.contacts[0].normal" defines direction of force, force is applied to center of rigidbody. ( after a little though I believe that it doesn't matter in this case because collider is sphere and hitpoint normal vector goes trough spheres center in every case, but is still wrong).

try: AddForce(-1*hit.contacts[0].normal, ...)

and this could be also usefull:

Debug.DrawRay(hit.contacts[0].point, hit.contacts[0].normal, Color.green, 20000, false);

avatar image White · Jul 04, 2012 at 08:26 AM 0
Share

Thank you very much! Now it kinda works:) I will tweak the physics a little until it gets realistic. And sorry for my wrong affirmation, I'm a beginner :P

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast not working during application of force 0 Answers

Adaptive Force smoothing? (Updated) 0 Answers

crush object based on pressure/weight from sides 1 Answer

maximum torque/maximum force 0 Answers

Calculate velocity to set to reach a target point on a plane considering the drag. 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