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
0
Question by Coaster-Mind · Apr 21, 2016 at 09:15 PM · rotationpositionaddforce

AddForce relative to child position and rotation?

Again a question.

I was thinking...

Is it possible to make the AddForce relative to a child on the object? Like position and rotation?

alt text

I've got the GameObject (Going to name it Motor) with this script:

 using UnityEngine;
 using System.Collections;
 
 public class Rotation : MonoBehaviour {
     public float Rotate = 10.0f;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKey("b"))
             transform.Rotate (Vector3.back * Rotate * Time.deltaTime);
     
     }
 }

And I want to apply its position and rotation to this AddForce :

 GetComponent<ConstantForce>().GetComponent<Rigidbody>().AddForce (-transform.right * aPower * Time.deltaTime);


Is this even possible? If yes, Please help me.

Thanks for reading!

test-222.png (1.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 Coaster-Mind · Apr 22, 2016 at 07:36 AM 0
Share

If this isn't possible then please tell me. Thanks -Coaster$$anonymous$$ind

avatar image Namey5 · Apr 22, 2016 at 10:07 AM 0
Share

Can't you just access the rigidbody through GetComponentInChild()?

avatar image Coaster-Mind Namey5 · Apr 22, 2016 at 11:27 AM 0
Share

No, Its not that easy. It needs to act like this link text

Will update my question soon with more and better info

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toromano · Apr 22, 2016 at 12:16 PM

You need to apply relative force to the ship's rigidbody.

 GameObject ship; //specify this
 GameObject engine = ship.transform.GetChild(0); // assuming has only one rudder child
 RigidBody shipRb  = ship.GetComponent<RigidBody>();
 
 shipRb.AddForceAtPosition(-engine.forward, engine.transform.position); // assuming blue axis is the engine direction

Hope that helps.

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 Coaster-Mind · Apr 22, 2016 at 01:06 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class TestA : $$anonymous$$onoBehaviour {
     public GameObject ship;
     public Rigidbody shipRb;
     public Component Child;
     public GameObject engine;
 
 
     // Use this for initialization
     void Start () {
     }
     
     // Update is called once per frame
     void Update () {
         GameObject ship; //specify this
         GameObject engine = ship.transform.GetChild(0); // assu$$anonymous$$g has only one rudder child
         Rigidbody shipRb  = ship.GetComponent<Rigidbody>();
 
         shipRb.AddForceAtPosition(-engine.forward, engine.transform.position); // assu$$anonymous$$g blue axis is the engine direction
     
     }
 }
 

Like this? This givealt text errors.

test-222.png (21.1 kB)
avatar image toromano Coaster-Mind · Apr 22, 2016 at 01:31 PM 1
Share

Ok. I guess you are new to unity.

Try this:

 using UnityEngine;
 using System.Collections;
 
 public class TestA : $$anonymous$$onoBehaviour
 {
     Rigidbody shipRb;
     Transform engine;
     public float thrust = 10f;
 
     // Use this for initialization
     void Start()
     {
         engine = transform.GetChild(0).transform;
         shipRb = GetComponent<Rigidbody>();
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         shipRb.AddForceAtPosition(-engine.forward * thrust, engine.transform.position);
     }
 }

Add this script to to ship gameobject

avatar image Coaster-Mind toromano · Apr 22, 2016 at 06:02 PM 0
Share

Well. Thanks for trying to help me but its uncontrollable. Direct when I launch the game the object keep gaining speed. Im very very thankful of your help.

Here the link to a test Click here

Also I think I might set this project to wait until I have more experience.

And yes. Im new to Unity and scripting.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to write a script to disable position and rotation tracking for VR 0 Answers

How would I go about finding the rotation corrresponding to the force added to the y and z axis of a object? 1 Answer

how to set rotation / position of an object on trigger? 2 Answers

if (transform.rotation == Vector3(0,0,0)) doesn't work! 2 Answers

Player not facing the mouse correctly 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