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 /
This question was closed Aug 15, 2019 at 03:53 PM by me-der for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by me-der · Aug 15, 2019 at 02:24 PM · 2drotateaddforce

Addforce ignores Rotation ?

So I have a Bullet that I want to disappear after 1 second and instantiate 8 smaller bullets that will fly in 8 directions. Here is an example of 2 bullets:

 Shott1 = GameObject.Instantiate(Bulle, transform.position, transform.rotation);
                 Shott1.GetComponent<Rigidbody>().AddForce(transform.right * 300f);
                 Destroy(Shott1, 1.5f);
     
     Shott2 = GameObject.Instantiate(Bulle, transform.position, transform.rotation);
                 Shott2.transform.Rotate(0, 0, 90);
                 Shott2.GetComponent<Rigidbody>().AddForce(transform.right * 300f);
                 Destroy(Shott2, 1.5f);

So the first bullet is as it should, but second should rotate 90 degrees and then go it's right, but it ignores rotation and goes in the same direction as the first bullet. I would use "transform.up" but I want bullets to go in 8 directions, not 4 (right,up,-right,-up and between). I would Instantiate them in a good direction but I don't understand what "w" is in Quaternion.

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0

Answer by Harambe_Reborn · Aug 15, 2019 at 02:53 PM

Instead of AddForce() use AddLocalForce() with a direction of transform.x.

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 me-der · Aug 15, 2019 at 03:16 PM 0
Share

I in my version there isn't AddLocalForce() but there is sth called AddRelativeForce but when I use it with:

  • "transform.right" doesn't work (bullet goes not in the direction it was rotated to)

  • "transform.x" says that there I can't write "x"

  • "transform.rotation.x" says it can't convert float to Vector3

  • "(new Vector3(1,0,0)" bullet that goes in the same direction is ok, but second bullet (rotated 90 degrees) is still in one place

  • "(new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)" either doesn't work

avatar image Captain_Pineapple me-der · Aug 15, 2019 at 03:48 PM 1
Share

take a second and think of what you wrote.


you want to take the rotation of the bullet into account and not the rotation of the object whatevery your script is on....


  • take Shott2.transform.right and you should be fine...


In general, even if it is not the best form of debugging: check the vectors you choose by a debug.log to see if it is actually the result that you hope for.

avatar image me-der Captain_Pineapple · Aug 15, 2019 at 03:51 PM 0
Share

Oh... So, as usual, I am making simple/stupid mistakes. Anyway, thank you.

Follow this Question

Answers Answers and Comments

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

Related Questions

rotate object that has FixedJoint2D 1 Answer

problem with rotation 2D 1 Answer

Rigidbody2d addforce isn't moving character 1 Answer

Need help on my script to calculate gravity for a mass 1 Answer

How do you AddForce to a rigidbody2D in the direction of a joystick? 0 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