move mouse within window using pyautogui - ui-automation

using opencv I am able to detect an object in a game. However, when my mouse moves over to the coordinate (in the actual game window), its using absolute coordinate (based on monitor pixel). So when I move my actual game window, its no longer clicking at the right spot.
Is there a way to move the mouse within the game window? For example, say if my game window is 500x500, and rectangles is detected say at (100, 100), is there a way to mouse over (100,100) relative to the game window? because if I move my game screen, I still want my mouse to be able to move to the same location.

Related

Is it possible to get position in 2D scene WITHOUT script?

I have placed a png background to my game, and i would like to know the position of certain element in the background (the top on the tree, i have pointed with red arrow)
I would like to know the 2D position of this tree top. I want to click with mouse on the tree top and get the position.
I don't want to use script.
I need to know a lot of locations in the background and i want to get them while the game is not played, but rather when i am in editor mode in the scene view, as shown in the picture.
Is this possible?
Pretty simple. Click the + in the top left of the Hierarchy, and add an Empty GameObject. Make sure it's Z position is the same as your background, and move it using the handles in the scene to the top of the tree. Once there, look at the position on the right, and that is the position of that point.

Move player in all directions with touch?, Unity

I was creating a basic scenario in Unity. Thi scene have 1 cube in the center of the room, and 1 camera(player).
I need to move the player around the cube like if was flying ( with movements at the top, bottom, left, right, inside and outside), very similar to when we move freely with the mouse on the development screen.
I need make this movement with the touch.
How can i to do?
Thanks!!
You can achieve almost all movements you want using a standard fps mobile controller: 1 joystick and a slide area for rotation. Your forward movement will be your player's forward direction(with W in unity you move always forward) and of course transform's left/right for strafe.
The tricky part is move up/down part(even in Unity editor you have to use 2 extra keys, Q&E) but you can always move up/down just looking in that direction.
if u use the unity standard asset 'cross platform input' (which is available in the standard asset pack for free,) then anything you program with a mouse event or click, will automatically call the corresponding touch event if use on a phone.

Unity: Drag on Screen and instantiate game object

How can I continuously instantiate Game objects by dragging on screen with unity and making the game object to follow the direction of the dragging?
For example: Drag right instantiates right, Drag up instantiates up or drag upwards at a certain angle and instantiates accordingly.
I don't know what you have done so far or how good you are in programming, but the basic principle would be
Create a DragInstantiate Script, which you put on a GameObject on your Scene, but not the one you want to Instantiate.
In the Update Method of this Script you have to check, if the left mouse button is pressed down. https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html
When you registered the click you have to save the position of the click. https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
The next step is to check when the left mouse button is released and again save the position. https://docs.unity3d.com/ScriptReference/Input.GetButtonUp.html
From these two positions you can really easy calculate the direction, in which the object should move. https://docs.unity3d.com/Manual/DirectionDistanceFromOneObjectToAnother.html
The last thing is to instantiate the object and set it's moving direction. https://docs.unity3d.com/Manual/InstantiatingPrefabs.html

Make an object rotate according to mouse movement. [UNITY C#]

I’m starting a learning project. The idea is that you have an archer character that is static, that has a bow attached to it that shoots arrows to targets of varying difficulty.
Turns out that right at the start I’m stuck. How do I make it so that the bow rotates when the player clicks and holds the mouse anywhere on the screen? So I click+hold and move left/right and the bow rotates left/right to aim the shot. I’d like to also eventually make it portable to phones (so you’d tap+hold etc).
Stack Overflow isnt a code writing service but i will explain what you must do:
Method 1 (Exact Aiming):
For every frame the mouse is down:
Make a Ray from a screen point... hint (use
camera.ScreenPointToRay).
Get a far point along the Ray using ray.GetPoint(distance);.
Bow.Transform.LookAt(newPoint, Vector3.Up);.
Method 2 (Continuous Movement):
Make a variable oldMousePos to store a Vector2 location.
Record your initial screen click position into that variable on a
mouse down event.
Have a function that runs once every frame the mouse stays down.
For the direction of the rotation of the bow, you can use
(newMousePos - oldMousePos).normalized;.
For the speed of rotation for your bow, you can use (newMousePos -
oldMousePos).sqrMagnitude;.

How to manage borders of a sprite using SpriteKit

I am just starting with SpriteKit, and I want to make a ball fall into a box...
I designed an open 2d square to act as a box. Whenever I launch the project, the ball doesn't enter the box, it rolls to one side. The background for my box is transparent.
If I haven't explained it well enough, I would basically like to know if I can make a sprite (ball) enter my other sprite (box), from one angle, but not be able to get into the box from a side angle...