Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
blueagardq13

Applying Force to Instantiated object (C#)

Question

Please login or register to see this code.

I DONT UNDERSTAND WHEN I INSTANTIATE THE PREFAB IT DOES NOT MOVE IT JUST STAYS THEIR. I HAVE TRIED ALMOST EVERYTHING, I DONT UNDERSTAND WHY IT DOES NOT APPLY FORCE. PLZ COMMENT BELOW ON HOW TO HELP ME. :) THANKS 

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Because you are adding force to a prefab, not the instance. Add force to myPrefabBullet after you uncomment everything.

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

got an error

cannot implicitly convert type 'UnityEngine.Object' to 'UnityEngine.GameObject'

Share this post


Link to post
Share on other sites
  • 0

Oh yea i forgot its c#

GameObject myPrefabBullet = Instantiate(prefabBullet, transform.position, shootPosition.rotation) as GameObject;
    myPrefabBullet.rigidbody.AddForce(shootPosition.right * shootForce);

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Themars2011 test it. it does not apply force idk why it just stays. its very wierd

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

 

proably because of the shootPosition.right, try this:

myPrefabBullet.rigidbody.AddForce(myPrefabBullet.forward * shootForce);

Share this post


Link to post
Share on other sites
  • 0

Tnx @themars2011 you helped me a lot it works and one more suggestion to all of you if you are making rocket launcher or bullets anything make sure that your rigidbody has low weight and it has useGravity checked to true because if the bullet or rocket is too weight it will just fall down I won`t took the force from the script.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

It does work, you just did it wrong... anyway, themars got it right so yeah.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...