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 D3m0nE · Aug 08, 2013 at 03:46 AM · 2drotategun

Problem in 2D Gun Rotation

Hello everyone

![alt text][1]

as u can see in picture

when i aim in the right side my Gun is Okey

but when i look/aim at the left side my Weapon Flipped Vertical

Used Code :

     private var mousePos : Vector2;
     private var screenPos : Vector3;
      
     function Update () {
     
     
    mousePos = Input.mousePosition;
    screenPos = Camera.main.ScreenToWorldPoint(Vector3(mousePos.x, mousePos.y, transform.position.z - Camera.main.transform.position.z)); 
    transform.rotation.eulerAngles.z = Mathf.Atan2((screenPos.y - transform.position.y), (screenPos.x - transform.position.x))*Mathf.Rad2Deg;
   
   }
errrrrrr.png (9.4 kB)
errrrrrr.png (9.4 kB)
Comment
Add comment · Show 2
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 robertbu · Aug 08, 2013 at 03:53 AM 0
Share

Don't open a new question just because you are not getting answers fast enough.

http://answers.unity3d.com/questions/509768/unity-2d-rotate-problem.html

Good luck.

avatar image D3m0nE · Aug 08, 2013 at 04:03 AM 0
Share

thx for help @robertbu but i guess this question. is alot easier to understand :)

1 Reply

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

Answer by clunk47 · Aug 08, 2013 at 11:49 AM

So this is a plane in 3D space with a texture applied? Why not just flip the texture on the Y axis by changing the scale? Have a look at SetTextureScale

 renderer.material.SetTextureScale("_MainTex", new Vector2(1, -1));

Comment
Add comment · Show 4 · 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 D3m0nE · Aug 08, 2013 at 01:36 PM 0
Share

okey i found the correct code and its working find

 transform.localScale = Vector3(transform.localScale.x , transform.localScale.y * -1, transform.localScale.z);


but now how i can decide if the mouse in right side or left side?

avatar image clunk47 · Aug 08, 2013 at 03:30 PM 3
Share
 using UnityEngine;
 using System.Collections;
 
 public class Example : $$anonymous$$onoBehaviour 
 {
     Vector2 mouse;
     
     void Update()
     {
         mouse = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
     
         if(mouse.x < Screen.width / 2)
         {
             print("$$anonymous$$ouse is on left side of screen.");
         }
     
         if(mouse.x > Screen.width / 2)
         {
             print("$$anonymous$$ouse is on right side of screen.");
         }
     }
 }
 
 
avatar image clunk47 · Aug 09, 2013 at 03:30 AM 1
Share

ahhhh no vote up? lol j/k j/k

avatar image D3m0nE · Aug 09, 2013 at 05:16 PM 0
Share

help me here :) http://answers.unity3d.com/questions/511157/shooting-accuracy-problem.html

u will get double vote

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

Multiple Cars not working 1 Answer

Rotate child of FPS when camera moves on Y-axis 2 Answers

problem with rotation 2D 1 Answer

Object won't rotate correctly 2 Answers

How to flip 2d GameObject based on direction? 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