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 beetrootpie · Jul 22, 2013 at 04:57 PM · 2dshootingprojectiletopdownorthello

Top down 2d shooting - XZ rotation

I'm trying to shoot a projectile in the direction of the mouse cursor, but for some reason with my current code I can't get it to move in the Z direction. It will only follow the mouse on the X plane, the degree of Z rotation seems to just modify the speed at which the projectile moves, I used the code below from the answer by aldonaletto in this question to help me, but I don't fully understand this part:

 transform.Rotate(0,Input.GetAxis("Horizontal")*60*Time.deltaTime,0);
 transform.Translate(0,0,Input.GetAxis("Vertical")*10*Time.deltaTime);

Why 60 and 10? and why rotate horizontally but translate vertically? I tried removing this code and messing around with it to see what it does but it doesn't seem to affect the projectile in any way. I use orthello 2d, could that be affecting it?

Here's the full code from the answer I'm talking about - it's what I'm using to shoot a projectile.

     var bullet:GameObject;
     var BulletSpeed:float = 20;
      
     function BulletShot(){
      
     var myPos = transform.position;
     var dist = Camera.main.transform.position.y-myPos.y;
     var x = Input.mousePosition.x;
     var y = Input.mousePosition.y;
     var dir = Camera.main.ScreenToWorldPoint(Vector3(x, y, dist))-myPos;
     var BulletClone = Instantiate(bullet, myPos, Quaternion.LookRotation(dir));
     BulletClone.rigidbody.velocity = dir.normalized * BulletSpeed;
     Physics.IgnoreCollision(BulletClone.collider, collider);
     Destroy(BulletClone,5);
     }
      
     function Update(){
      
     transform.Rotate(0,Input.GetAxis("Horizontal")*60*Time.deltaTime,0);
     transform.Translate(0,0,Input.GetAxis("Vertical")*10*Time.deltaTime);
     if (Input.GetButtonDown("Fire1")){
     BulletShot();
     }
     }

Any help would be very appreciated :)

Comment
Add comment · Show 1
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 Benproductions1 · Jul 23, 2013 at 02:21 AM 0
Share

Rotation is done around an axis. $$anonymous$$eaning rotation on the Y axis, rotates it left and right.
Translation is done on an axis. $$anonymous$$eaning translating on the Z axis translates it forward and back.

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

shooting in 2d problem 0 Answers

Shooting projectiles in 2D world 2 Answers

2D Top Down Shooter Shooting Problems 1 Answer

How do I get my character to shoot a projectile in the direction of the cursor? 1 Answer

How to make Enemy shoot at Player Top Down 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