• 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 maninduw · Jan 28, 2014 at 07:23 AM · positionforce

Adding relative force at a position

Hello, Is there a way to add relative force to a rigidbody at specified position ? .

Eg: I have a rectangular object on the screen. When I press A, a relative force should be added to the upper left corner of the object and when I press D, a relative force should be added to the upper right corner of the object.

Thank you.

Comment
Add comment · Show 4
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 Theinsanekiller · Jan 28, 2014 at 07:47 AM 0
Share

I am not so sure but, i guess you do it using an empty gameobject. Place that empty game object on the left or right corner and add relative force to it. It should work

avatar image maninduw · Jan 28, 2014 at 08:22 AM 0
Share

Thank you for the tip. I'll try it out.

avatar image clondon00 · Jun 21, 2015 at 11:32 AM 0
Share

What am I doing wrong? I keep getting errors on

   // Vertical Thruster Positional $$anonymous$$ethod (making a thruster that is the child of a rigidbody)
 void Start() 
 {
     Vehicle = GetComponent<Rigidbody> ();
     Thruster$$anonymous$$chUp = GameObject.Find ("Thruster$$anonymous$$chUp");
 }

 void FixedUpdate() 
 {
     //transfor$$anonymous$$g the local Vehicle space into world coordinates
 NewPosition = Vehicle.transform.TransformPoint(Vehicle.transform.position);

   //Thruster ATTITUDE CONTROLS
     //$$anonymous$$ch Up
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) 
     {
         Vehicle.AddForceAtPosition (Thruster$$anonymous$$chUp.transform.position, NewPosition.up * ThrustAttitude);
     }

I've defined NewPosition as a Vector3, set it to equal the vehicle's position in world space, and am now trying to use that NewPosition vector's "up" direction to apply the Force at Position, since Add Force at Position only works in world coordinates as you say. Help!

avatar image clondon00 · Jun 21, 2015 at 11:33 AM 0
Share

What am I doing wrong (super noob here)? I'm trying to Add Force at Position on a Vehicle to make it pitch its nose up. I've followed the method above, but am getting stuck. I'm using C#.

I've done the following:

-Created a child object under the nose of the vehicle called Thruster$$anonymous$$chUp to get the position to apply the force to on Vehicle -Created a new Vector3 called NewPosition to store the world coordinates from the Vehicle's local position and am trying in the Fixed Update to Add Force At Position to the Vehicle at the Thruster$$anonymous$$chUp location using NewPosition as the force direction (trying to us ".up" there).

 public float ThrustAttitude = 10f;

 //Ship components
 private Rigidbody Vehicle;
 private GameObject Thruster$$anonymous$$chUp;

 //World position of Vehicle as it flies
 private Vector3 NewPosition;


 void Start() 
 {
     Vehicle = GetComponent<Rigidbody> ();
     Thruster$$anonymous$$chUp = GameObject.Find ("Thruster$$anonymous$$chUp");
 }

 void FixedUpdate() 
 {
     //transfor$$anonymous$$g the local vehicle space into world coordinates
 NewPosition = Vehicle.transform.TransformPoint(Vehicle.transform.position);


     //$$anonymous$$ch Up
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) 
     {
         Vehicle.AddForceAtPosition (Thruster$$anonymous$$chUp.transform.position, NewPosition.up * ThrustAttitude);
     }



Constant error. What's wrong here?

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by GameVortex · Jan 28, 2014 at 08:11 AM

There is no AddRelativeForceAtPosition, but you can translate the local position you have into world space before applying the force:

 Vector3 worldForcePosition = transform.TransformPoint(yourLocalForcePosition);
 rigidbody.AddForceAtPosition(force, worldForcePosition);
Comment
Add comment · Show 1 · 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 maninduw · Jan 28, 2014 at 08:22 AM 0
Share

Thank you very much. I'll try it out.

avatar image
0

Answer by trudeaudm · May 06, 2014 at 06:45 PM

Just do

rigidbody.AddForceAtPosition(transform.forward * 10, transform.position);

transform.forward or whatever direction will keep it relative to the transform.

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

23 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 avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Problem stopping rigid body after adding a force 0 Answers

Add force at position with respect to rotation 1 Answer

Apply force from specific location in space 0 Answers

How to apply a force forward depending of the camera 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