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 /
This question was closed Oct 31, 2014 at 07:30 PM by robertbu for the following reason:

Duplicate Question

avatar image
0
Question by fireant911 · Oct 31, 2014 at 07:30 PM · instantiate-game-object

AddForce not working on Instantiated Object

I had an object that was in my hierarchy and when certain conditions were met, a force (AddForce) was applied. This worked very well until I made a prefab out of the original object… now, the object is instantiated and it just drops till it hits the floor and the AddForce does nothing. I searched and it appears that applying a force to an object that has been instantiated has been problematic yet nothing I have read or tried over the past six hours seems to make any difference.

The object I am attempting to AddForce to is ‘tire_wheel_prefab_2’. Again, before this became a prefab and was instantiated, it worked perfectly. On the ‘tire_wheel_prefab_2 there is a Rigidbody added, ‘Use Gravity’ is checked, and ‘Is Kinematic’ is unchecked. The settings are identical to the object I used before (when it worked) but AddForce is doing nothing. The ‘sphere’ and ‘heart_2’ commands immediately above the AddForce do exactly what they are supposed to so I know that the conditions are being met.

Can someone assist me in getting the AddForce to work properly?

Sincerely,

Daryl G

 using Phidgets;
 using Phidgets.Events;
 using UnityEngine;
 using System.Collections;
 
 public class PhidgetsController : MonoBehaviour
 {
     private InterfaceKit InterfaceKitController = new InterfaceKit();
     private int arbitraryCounter = 0;
     private int oldarbitraryCounter = 0;
     public new ParticleSystem particleSystem;
 
     public GameObject sphere;
     public GameObject heart_2;
     public Rigidbody tire_wheel_prefab_2;
     public GameObject TextHintGUI;
     TextHints bPScript;
     public bool playsound = false;
 
     void Start()
     {
         particleSystem.Stop();
         Instantiate (tire_wheel_prefab_2, new Vector3(5.6f, 6f, 6f), Quaternion.Euler(270, 0, 0));
     }
     
     //Sensor Change event handler...Display sensor index and new value to the console
     void InterfaceKit_SensorChange(object sender,SensorChangeEventArgs e)
     {
         arbitraryCounter = e.Value;
     }
     
     void FixedUpdate()
     {
         if (arbitraryCounter>oldarbitraryCounter) {
             particleSystem.Play();
             if (playsound==false) {
                 audio.Play();
                 playsound=true;
             }
 
             bPScript = TextHintGUI.GetComponent <TextHints>();
         //if high bp is NOT selected (i.e., normal bp)
         if (bPScript.whichBPOption == false) {
             sphere.transform.localScale += new Vector3(((arbitraryCounter-500)/50) * Time.deltaTime, ((arbitraryCounter-500)/50) * Time.deltaTime, ((arbitraryCounter-500)/50) * Time.deltaTime);
             heart_2.transform.Rotate(Vector3.right, 20 * Time.deltaTime); //this rotates heart when pumping
             tire_wheel_prefab_2.AddForce(-30,5,10);


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 robertbu · Oct 31, 2014 at 07:32 PM 0
Share

A prefab is like a blueprint. It is used to construct real object. You are applying your force to the prefab, when what you want to do is apply force to the newly created object. Save the return value of the Instantiate in a class instance variable:

  tire = Instantiate (tire_wheel_prefab_2, new Vector3(5.6f, 6f, 6f), Quaternion.Euler(270, 0, 0)) as Rigidbody;

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How can I have an access to the rigidbody component of each instantiated object? 1 Answer

[Solved] Storing a GameObject in a var and then instantiating it in a new scene? 2 Answers

Instantiate an instance? 1 Answer

[4.6] Instantiating an object within a ScrollView makes the object invisible 0 Answers

Instantiate script for randomly selecting sound is suddenly creating New Game Object in hierarcy?? 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