- Home /
getkeydown keyboard arrows
Hey everyone.
I have a code that when the player touches (or clicks with mouse) any location on the screen it will go to it's closest corresponding anchor point.
here is the example code of how i've restricted screen movement.
_myPosition = _touchPosition;
if (_myPosition.x >= 0f && _myPosition.x <= 3.5f && _myPosition.y >= -6f && _myPosition.y <= -1.2f)
{
_myPosition = new Vector3(1.74f, -2.4f, 0);
}
I'm trying to figure out how to do this with the arrow keys. Im pretty sure I have write one for each arrow (ie keycode.leftarrow etc), but i'm not sure what the starting point is for
if (input.getkeydown(keycode.leftarrow)
{
//what is supposed to go here to make it move from point 1 to point 2
}
there are already many tutorials on the internet about this.
I realize this but the problem is controlling it to not move beyond the points or not be stuck in the current location. That's the current problem I have I can't seem to get unstuck from the first control point or stop at the next control point.
So the internet tutorials that I've looked at would require me to remove my current movement methods. I want them all to work concurrently.
Answer by greasemonkeyandy · May 23, 2019 at 12:59 AM
your best bet (aka easiest) is to make a list of the anchor points in the order you want people to scroll through them, and then when they hit left/right it simply iterates to the next point. Otherwise you would have to take the dot product of the difference vector and the direction of choice vector(left/right/up/down) of each point and select the closest to 0.
Your answer
Follow this Question
Related Questions
How do i move around in the editor without using arrow keys or middle click. 1 Answer
Isometric movement using arrow keys? 1 Answer
Detecting left and right being pressed at the same time. 1 Answer
local jumping and diagonal movement 1 Answer
Fixing Issues with custom RTS Camera Controll Script 1 Answer