|
I am currently trying to rotate an object around its pivot point. It's pivot point is placed at the back left of the image (note: working with 2D planes). This works fine and all but I am intending to mathf.Clamp the axis between 0 and 90. The issue I am having is that when you approach 90 degree whilst moving your finger it kind of dies off at 80 degrees so its not a crisp movement. If you take your finger off and move it, it works fine but of course you want the ability of one smooth up and down motion without having to remove and move the object again. It has to do with the rotation, I can't think of another way that would do it, I worked with Euler and Quaternion but it seems if you extend your finger to the outset of the barrel and move it, it works better. Essentially the only other solution I can think of is creating an invisible plane at which the cannon barrel looks at (snaps to) and follows on wards but this seems rather unnecessary. Code below, its all very hard coded for now till I can resolve this issue. using UnityEngine; public class CannonBarrel : MonoBehaviour { } } }
(comments are locked)
|
|
I have changed the way I am going about this using the lookAt function. transform.LookAt(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Abs(Camera.main.transform.position.z)))); I still can't seem to get this working, it just rotates in random axis. I've tried locking the axis but I don't know whats going on.
(comments are locked)
|
|
After a lot of searching an multiple trials I have a solution if anyone was curious. Essentially this allows the object which is a 2D plane to follow mouse and finger input. //NewRotationWithMouse() public Vector3 mouse_pos; public Transform target; public Vector3 object_pos; public float angle; void Update() { NewRotationWithFinger(); //NewRotationWithMouse(); } mouse_pos.z = 5.23f; //The distance between the camera and object object_pos = Camera.main.WorldToScreenPoint(target.position); mouse_pos.x = mouse_pos.x - object_pos.x; mouse_pos.y = mouse_pos.y - object_pos.y; angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); } If this doesn't work feel free to contact me.
(comments are locked)
|
