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 bakos · Feb 07, 2014 at 10:32 PM · constantforce

hit.parent doesn't work when applied to physics GameObjects using Constant force

Hello guys! I am having a problem with some code.

I have a build script which attaches cubes (ship components) to other cubes (ship components) and to this day it is working PERFECTLY!

Only issue I am having now is that when i attach a constant force to this object, and try to child one of the other cubes to it, the cube refuses to child itself to that parent cube.

  • Before i added constant force to the parent cube, it worked fine and each cube child'd itself just fine. They would all move with the parent and so on.

Is there anything i am missing here or something i have forgotten to do?


Script:

 var blockLayer : LayerMask = 1;
 var range : float = 100;
 var hit : RaycastHit;
 
 var blocks : GameObject[];
 var chosenB : GameObject;
 
 static var shipStart : boolean;
 var shipBegin : GameObject;
 var shipParent : Transform;
 var shipSpawn : Transform;
 
 var player : Transform;
 var instantiatedObject;
 var isC = false;
 ////////////////////////////////////////////////////
 var snapDirections : Vector3[];
 var closestSnapDirection : Vector3;
 var forwardVar : Vector3;
 ////////////////////////////////////////////////////
 
 function Update () {    
     
     snapDirections[0] = Vector3.right;
     snapDirections[1] = Vector3.left;
     snapDirections[2] = Vector3.forward;
     snapDirections[3] = Vector3.back;
     //snapDirections[4] = Vector3.up;
     //snapDirections[5] = Vector3.down;
     
     if(Input.GetKeyDown(KeyCode.Alpha0))
     {
         chosenB = null;
     }
     if(Input.GetKeyDown(KeyCode.Alpha1))
     {
         chosenB = blocks[0];
     }
     if(Input.GetKeyDown(KeyCode.Alpha2))
     {
         chosenB = blocks[1];
     }
     if(Input.GetKeyDown(KeyCode.Alpha3))
     {
         chosenB = blocks[2];
     }
     if(Input.GetKeyDown(KeyCode.Alpha4))
     {
         chosenB = blocks[3];
     }
     if(Input.GetKeyDown(KeyCode.Alpha5))
     {
         chosenB = blocks[4];
     }
     if(Input.GetKeyDown(KeyCode.Alpha6))
     {
         chosenB = blocks[5];
     }
     if(Input.GetKeyDown(KeyCode.Alpha6))
     {
         chosenB = blocks[6];
     }
     if(Input.GetKeyDown(KeyCode.Alpha7))
     {
         chosenB = blocks[7];
     }
     if(Input.GetKeyDown(KeyCode.Alpha8))
     {
         chosenB = blocks[8];
     }
     
     if (Input.GetMouseButtonDown(0))
         Build();
     if (Input.GetMouseButtonDown(1))
         Erase();
     
     
     if(Input.GetKeyDown(KeyCode.B))
     {
         shipStart = !shipStart;
         isC = true;
     }
     
     if (Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer)) 
     {
         chosenB.transform.position = hit.normal;
     }
     
 }
  
 function Build() {
 
     if (HitBlock() && hit.transform.tag == "Block" || HitBlock() && hit.transform.tag == "Helm" || HitBlock() && hit.transform.tag == "Weapons") 
     {
 
         
         var dotProductClosestToOne = Mathf.NegativeInfinity;
         var playerForward = player.transform.forward;
         for(i = 0; i < snapDirections.Length; i++) ///////////////////////////
         {
             var currDotProduct : float = Vector3.Dot(snapDirections[i], player.transform.forward);
             if(currDotProduct>dotProductClosestToOne)
             {
                 dotProductClosestToOne = currDotProduct;
                 closestSnapDirection = snapDirections[i];
             }
         }/////////////////////////////////////////////////////////////////////
         
         var interF = GameObject.Instantiate(chosenB);
         interF.transform.rotation = Quaternion.LookRotation(closestSnapDirection, Vector3.up);
         interF.transform.position = hit.transform.position + hit.normal;
         interF.transform.parent = hit.transform.parent;
     }
 }
  
 function Erase() {
 
     if (HitBlock() && hit.transform.tag == "Block" || HitBlock() && hit.transform.tag == "Helm" || HitBlock() && hit.transform.tag == "Weapons")
         Destroy(hit.transform.gameObject);
 }
  
 function HitBlock() : boolean {
     return Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer);
 }
 
 
 function OnGUI()
 {
 
     
     if(shipStart == true)
     {
         
         if(GUI.Button(Rect(1,1,100,20), "Create Ship"))
         {
             var ship = Instantiate(shipBegin, shipSpawn.transform.position, Quaternion.identity);
             shipP = Instantiate(shipParent, shipSpawn.transform.position, Quaternion.identity);
             ship.transform.tag = "Block";
             ship.transform.parent = shipP.transform;
              
         }
     }
 }


Any hep would be greatly appreciated! Thank you once again for reading, Sincerely,

bakos

Comment
Add comment · Show 1
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 bakos · Feb 07, 2014 at 10:55 PM 0
Share

As an update i seemed to have found a problem within my code, but it does not fix my issue.

if i change:

 interF.transform.parent = interF.collider.transform.parent;

It does the same thing. It leaves the children outside of the parent. Although if i change it to:

 interF.transform.parent = interF.collider.transform;

It applies the child to the parent, but deleting any one of these children would delete the entire creation.

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Add wind effect to Game Object 1 Answer

what is the comand for global torque using constant force 1 Answer

ConstantForce on RigidBody2D 0 Answers

Constant Running on x axis 0 Answers

keep my collider on my particle system close together 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