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 /
avatar image
0
Question by inkynoodles · Jul 09, 2017 at 03:06 PM · 2d2d-physicstopdown2d rotation

2D top down shell ejection

Hi, I've been trying to figure this out for days. Some codes I've tried work but not as quite as i want it to work. I have the shell ejection working fine when I use transform.translate but when i use AddForce the shells just floats to the left. I finally have the shell to rotate on its own axis as other codes i have tried would rotate it according to the position of its parent, which shows the shell floating all over the place. I also have a box collider comp on the shell but set as is triggered so it would not collide with the player collider. Not sure if that matters.

What am I doing wrong?

Any help will be appreciated!

My code:public class ShellEjectionCtrl : MonoBehaviour {

 public float ejectSpeed;
 public float rotspeed;


 void FixedUpdate(){


     transform.Translate(new Vector2 (-2,ejectSpeed)*Time.deltaTime); //this code works properly the shell gets affected by gravity but rotates weird like it has a point of rotation.

     GetComponent<Rigidbody2D> ().AddForce (new Vector2(-2,ejectSpeed));//this code makes the shell float to the left position but shell rotates properly

     GetComponent<Rigidbody2D> ().AddTorque (Random.Range (0, rotspeed));//rotates the shell not relative to its position i.e ejection port of the rifle
     Destroy (gameObject, 2.0f);                                            

 }

}

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by FortisVenaliter · Jul 09, 2017 at 03:24 PM

Well, it's physics. When a shell is ejected, it only gets the force applied as it's actually ejected, not when it's flying through the air. You need to add the force and torque at the moment of ejection, and just let the physics system handle it from there.

Comment
Add comment · Show 2 · 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 inkynoodles · Jul 10, 2017 at 12:05 AM 0
Share

So how would I go about it? Should I modify the Instantiate function?

avatar image inkynoodles · Jul 10, 2017 at 01:03 AM 0
Share

Wasn't very clear but it led me to the right direction. Finally working how I wanted it to work. Thank You so much!

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

123 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

Related Questions

RotateAround using physics 1 Answer

Why is the Unity 2D physics engine only deterministic when Z axis rotation is frozen? 0 Answers

I'm attempting to make a character face the joystick in a top down unity2d game. 1 Answer

Look for the player isn't working 1 Answer

2D Directional top down movement,Topdown 2d Directional Movement 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