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 Jan 23, 2018 at 01:55 AM by theElderOne for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by theElderOne · Jan 22, 2018 at 06:18 PM · 2d game2d-platformer2d-physicsplatformerfor-loop

Rigidbody2D.AddRelativeForce not working

I'm making an action platformer. I'm having the player shoot a shot gun with a spread shot like this (excuse the lack of drawing skills I can't draw): alt text I'm using Rigidbody2D.AddRelativeForce But for some reason the bullets don't move forward, they spawn but just sit there. Here's a picture of the Rigidbody on each bullet. I do want to be adding local force, so they can seperate alt text

And finally here's the relevant code from the player script:

 void ShootWeapon()
 {         
     for (float j = -bulletSpreadAngle; j < bulletSpreadAngle; j += bulletSpreadAngle / numOfBullets * 2)
     {
         GameObject bullet = Instantiate(bulletPrefab, gunEnd.position, Quaternion.identity);
         Rigidbody2D projectileRigidbody = bullet.GetComponent<Rigidbody2D>();
         print(j);
 
         bullet.transform.localRotation = new Quaternion(Quaternion.identity.x, Quaternion.identity.y, j, Quaternion.identity.w);
         projectileRigidbody.AddRelativeForce(new Vector2(bulletSpeed, projectileRigidbody.velocity.y), ForceMode2D.Impulse);
     }
 }

quick-pic.png (33.6 kB)
picture-of-rigidbody.png (23.2 kB)
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 NoobGaming · Jan 22, 2018 at 06:27 PM

I'm guess that the "Body Type Kinematic" might be your problem? Being kinematic means the rigidbody doesn't get forces applied to it. Try changing that up. Hope this helps!

Comment
Add comment · Show 5 · 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 theElderOne · Jan 22, 2018 at 07:08 PM 0
Share

Yes, changing the Rigidbody to dynamic and setting the gravity scale fixed the problem. However, they don't move along the local axis as I had hoped. any help on that?

avatar image NoobGaming theElderOne · Jan 22, 2018 at 08:24 PM 0
Share

Awesome! We'll it depends how you have you gameobject positioned. You have projectileRigidbody.velocity.y which is the up axis. If you want it to fly forward then do projectileRigidbody.velocity.x

Hope that helps!

avatar image theElderOne NoobGaming · Jan 22, 2018 at 09:05 PM 0
Share

They go along the global x axis but not on the local x axis

Show more comments

Follow this Question

Answers Answers and Comments

87 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

Related Questions

Player getting stuck between grounds 0 Answers

,Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis). 1 Answer

Can anybody help me with this? Character bodying is falling apart. 0 Answers

How to move a character in front of a collider and be able to jump and be on top of the said collider? 1 Answer

Help Me! I want to make a pixel fairy! 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