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 SteenPetersen · Feb 04, 2018 at 08:55 PM · projectilemouseposition2.5d

Projectiles in 2.5D game

Hi there I am making a 2.5D game so basically a 2d top down game but I have taken my camera and angled it -30 on the x rotation. this way I can put in 3d elements as well and I really like the style.

However I have run into a probelm with projectiles.

In a normal top down game you can shoot a projectile at your mouse with this code:

             Vector3 mouse = Input.mousePosition;
             mouse = Camera.main.ScreenToWorldPoint(mouse);
 
             Vector2 direction = new Vector2(
                 mouse.x - transform.position.x,
                 mouse.y - transform.position.y
                 );
 
             Debug.DrawLine(transform.position, mouse, Color.cyan);

Well this draws a debug line but you get my drift. this will give you the correct direction to launch your projectile.

However I am unsure as to how to go about correcting for the -30 degree angle on my camera.

any help would be appreciated.

regards.

Comment
Add comment · Show 4
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 SteenPetersen · Feb 05, 2018 at 03:07 PM 0
Share

Still cant find how to compensate for the rotation of the camera.

Ways to reproduce.

Open a scene and make a script with the following code:

               //debug
               LineRenderer line;
 
              Vector3 mouse = Input.mousePosition;
              mouse = Camera.main.ScreenToWorldPoint(mouse);
 
             Vector3 direction = new Vector3(
                 mouse.x - projectilePoint.transform.position.x,
                 mouse.y - projectilePoint.transform.position.y,
                 mouse.z = projectilePoint.transform.position.z
                 );
 
             line.startColor = Color.cyan;
             line.startWidth = 0.1f;
             line.SetPosition(0, projectilePoint.transform.position);
             line.SetPosition(1, direction);


set the camera to position 0, -5.5, 0 rotation -30, 0,0

avatar image TreyH · Feb 05, 2018 at 03:17 PM 0
Share

Can you post a screenshot of your situation?

avatar image SteenPetersen · Feb 05, 2018 at 04:34 PM 0
Share

I solved this issue while responding to another user I wrote up my answer here:

https://answers.unity.com/questions/1460269/orthographic-camera-with-rotation-and-screentoworl.html?childToView=1464495#answer-1464495

avatar image SteenPetersen · Feb 05, 2018 at 04:38 PM 0
Share

On a side note, in case someone has the same situation as me. If you then wish to rotate your sprite "bullet" correctly, do this:

             // turn the projectile correctly
             float angle = $$anonymous$$athf.Atan2(direction.y, direction.x) * $$anonymous$$athf.Rad2Deg;
 
             projectile.transform.Rotate(0, 0, angle);

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

77 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

Related Questions

2.5D Isometric Move Character and Facing towards mouse 0 Answers

shoot forward and comeback 0 Answers

Getting 2D projectiles that fire in the direction of the mouse position to work in unity 5? 0 Answers

Point an arrow at the mouse position, 2.5D 1 Answer

Rotation troubles 2 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