- Home /
Problem in 2D Gun Rotation
Hello everyone
][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;
}
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.
thx for help @robertbu but i guess this question. is alot easier to understand :)
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));
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?
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.");
}
}
}
help me here :) http://answers.unity3d.com/questions/511157/shooting-accuracy-problem.html
u will get double vote
Your answer
Follow this Question
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