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 /
avatar image
0
Question by 24adithya · Jun 03, 2012 at 12:58 PM · 2d-physics2d-gameplayshooterorthographic

Smooth shooting in 2d orthographic camera

Hi,

I am new to Unity with developing 2D games. I am trying to shoot bullets in X and Y directions simultaneously. I am setting gravity to the bullet so that it comes down.

I am not able to have a smooth clean shoot possible. While reaching its(bullet) peak, it starts wobbling and while coming down it wobbles vigorously !

         float amountToMove = bulletSpeed * Time.deltaTime;
         
         //Move the bullet
         //transform.Translate(Vector3.up * amountToMove);//Working
         
         //Try to fire in a parabola
         float rightDir = (Vector3.right * amountToMove).x;
         float upDir = (Vector3.up * amountToMove).y;
         transform.Translate(rightDir, upDir, 0.0f);


I am using 'Orthographic' Projection.

I would like to have a clear parabola like motion without pauses/stoppages. Is there a way to do it ? I am referring to TheLorax's 2D game shooter tutorial.

Comment
Add comment · Show 3
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 24adithya · Jun 03, 2012 at 02:24 PM 0
Share

Nope. Is there a tutorial avaliable anywhere ? If you could point me to one that would be really helpful..

avatar image 24adithya · Jun 03, 2012 at 02:26 PM 0
Share

I have used Unity engines' Physics RayCast and LinceCast features to detect collision..but here i am not able to figure it out !

avatar image 24adithya · Jun 04, 2012 at 04:13 AM 0
Share

I have gone through VTC videos while developing a First Person Shooter using 3D tools.. m facing problems and am unclear when it comes to 2D .. anyway, can you point me to some link which will help me clear my concepts on the above mentioned points ? A tutorial would definitely help. I guess i am unclear because i haven't studied everything you mentioned completely ! :)

Thanks !

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Mortoc · Jun 03, 2012 at 01:34 PM

The problem is in your math. You are trying to create parabolic movement but both x and y axes are getting the same values. You want your x axis to have a constant speed and your y axis to lose height from gravity each frame.

alt text

I think you may have a different sort of bug in this code as well:

 float rightDir = (Vector3.right * amountToMove).x; 
 float upDir = (Vector3.up * amountToMove).y; 
 transform.Translate(rightDir, upDir, 0.0f);

that's the same as doing:

 transform.Translate(amountToMove, amountToMove, 0.0f);


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

Answer by BroVodo · Sep 02, 2012 at 01:48 PM

Personally I'd just add a rigid body to the bullet and use the add force function.

Look here.

 var bulletForce : Vector3 = Vector3( 10, 10, 0 );
 
 function Update()
 {
     if( Input.GetButtonDown( "Fire1" ) )
     {
         rigidbody.AddForce( bulletForce );
     }
 }

This script would need to be attached to the bullet and the bullet would need to also have a rigid body component as well. This wouldn't be good if you were going to have lots of bullets in the scene but you should be able to get the idea.

edit: use real world sizes, makes things much easier, especially if you want to work out where the bullet lands...

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D: Camera Size, in Orthographic Projection vs Scale of a Plane 2 Answers

How To Make Game Remember User Input Then Play It Out, But Backwards 4 Answers

Instantiated objects do not work with Hitboxes(2D) 0 Answers

Hello Im looking for help creating a script for spike or fire damage! 1 Answer

How to calculate the amount of overlap between two 2D objects. 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