- Home /
Move object along non-physical diagonal line
Hello,
This may be a simple maths issue or it could be much. much more complex. Hear me out...
The arm holding the pen (pictured below) can be moved around the ginormous sheet of paper using the keyboard arrow keys (up, down, left and right).
The player can draw black circles using the pen by holding down the X key. Over the white sheet of paper is a drawing guide with already drawn black circles (guide dots) at a 0.5 opacity.
Now, when the arm moves, I want it to move to the exact center of the next guide dot in the direction pressed by the player. The center of each guide dot is evenly spaced from each other, they are just different sizes.
What makes this difficult is that the guide dots are at an angle, and there are literally thousands of them. I've tried playing it by eye and guessing what the distance is from each guide dot, but by the time I've moved 10 spaces in any direction, the hand is out of sync with the guide dots.
Am I being stupid? How can I calculate it so that the hand moves to the center of the next guide dot exactly.
How did you prepare the dotted paper texture? Surely, whoever prepared the texture did not lay all these circles by hand. They must have used a transform filter to create an array of duplicate circles shifted by preset x and y distance and certain rotation. You can use that information to accurately position the arm.
Answer by podmaster · Sep 02, 2015 at 06:39 PM
I would contain the arm "Player" Object into an empty object which center 0,0,0 were on the exact end of the pen. (Sorry if my English isn't good enough :p) Then every time the player press an arrow set the position of the empty to the center of the circle.
Now... I think that the main problem is that the points aren't on a vertical or/and horizontal direction. You need to set some rules about what Up,Down,Left and Right mean.
Hope that helps.
Answer by cjdev · Sep 02, 2015 at 07:26 PM
You need to know two things about the dot's position: the distance between the centers of two dots and the angle from the "up" vector and the vector between two dots. Then to find the x offset you need to move you multiply the distance times the Cos of the angle, and to find the y offset it's the distance times the Sin of the angle. If you multiply those offsets in the appropriate direction with each user key press that should keep the hand in the middle of the dot each time.
Your answer
Follow this Question
Related Questions
Third Person Controller Rotation 0 Answers
Human model clothes 1 Answer
How to make an object rotate to raycast hit from mouse? Unity 3D 1 Answer
Materials and Textures are Stretching and Tiling doesn't help! 0 Answers
How to move your player or character left or right by 14 unit on button click in mobile 0 Answers