Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by HolBol · Jun 25, 2011 at 11:12 PM · rigidbodyaddforceatposition

rigidbody.AddForceAtPosition

I have this script:

 var ForceX : float = 0;
 var ForceY : float = 2;
 var ForceZ : float = 0;
 
 var positionx : float = 0;
 var positiony : float = 0;
 var positionz : float = 0;
 
 function FixedUpdate () {
 
     if(Input.GetKey(KeyCode.Tab)){
         rigidbody.AddForceAtPosition(Vector3(ForceX,ForceY,ForceZ), Vector3(transform.position.x - positiony, transform.position.y - positionx, transform.position.z - positionz)); 
     }
 }

This is supposed to fin the position on the object, then addforce at that point. But the weird thing is, no matter what i set the values too, it doesn't work. Any ideas?

Comment
Add comment · Show 2
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 aldonaletto · Jun 25, 2011 at 11:37 PM 0
Share

I tested this script and it worked for me. Have you checked if rigidbody rotation is enabled?

avatar image aldonaletto · Jun 25, 2011 at 11:44 PM 2
Share

By the way, you can optimize your code:

   var pos = Vector3(position.y,position.x,position.z);
   rigidbody.AddForceAtPosition(...,transform.position-pos);

It reduces accesses to transform.position from 3 to 1. Another thing: positionx and positiony are swapped in your script, so I swapped them in the vector pos too; is this an intended behavior?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Waz · Jun 26, 2011 at 05:09 AM

There is nothing wrong with your code in principle. A force of 2 Newtons might be too small to have an effect. How heavy is the rigidbody? What is the friction with the surface is it resting upon? These are factors that will counter such a force.

Comment
Add comment · Show 7 · 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 HolBol · Jun 26, 2011 at 10:56 AM 0
Share

O$$anonymous$$, I found the force i was applying was too small. But it doesn't, now, push it directly up- it tilts it at the same time. I might have to use animations ins$$anonymous$$d.

avatar image Waz · Jun 26, 2011 at 11:02 AM 1
Share

That's the purpose of AddForceAtPosition - it applies the force to a point other than the center of mass, and therefore imparts torque (twisting force). If you want to avoid twisting, just use rigidbody.AddForce.

avatar image HolBol · Jun 26, 2011 at 11:29 AM 0
Share

i needed add force at point though, because addforce is NOT what i need. I need the force to be under a certain part of the object to lift it, but ins$$anonymous$$d of going straight up, it leans at the same time.

avatar image Waz · Jun 26, 2011 at 12:25 PM 1
Share

Why do you need it at a certain part of the object? That's the entire reason it is tilting. If you lift a chair by pushing up on one leg, it tilts. If you push at its center of mass, if lifts without tilting.

avatar image Waz · Jun 26, 2011 at 12:33 PM 2
Share

Depends where the center of mass is. If you want very specific physics results, use AddForce and AddTorque. It's normal (and good) to make the physics engine do what the player expects, and what looks right, regardless of the laws of physics, which for game designers are just guidelines ;-).

Show more comments

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

6 People are following this question.

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

Related Questions

How do i add a force to multiple objects in an area? 1 Answer

AddForceAtPosition to Parent's rigidbody...C# 0 Answers

AddForceAtPosition Creating Torque When It Shouldn't 0 Answers

Gimbal Lock like behavior using AddForceAtPosition in child objects 0 Answers

Rigidbody.AddForceAtPosition & functions 1 Answer


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