L
L
Lecturer2020-04-24 13:51:05
JavaScript
Lecturer, 2020-04-24 13:51:05

How to move an element with arrows?

The question is. There is a block, for example a machine. You need to move it with the arrows, just moving in a straight line (vertically and horizontally) is not a problem. How to make it drive only in front, that is, the up arrow moves in the direction of the hood, down - reverse, turn the car left and right, but taking into account that I hold the up key or vice versa reverse. I hope I explained clearly.
Interested in how difficult it is to finish it in JS, or is it still easier to use canvas, although I don’t quite understand it yet?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-04-24
@lecturer_82

I threw an example, add it so that the turn depends on the speed so that when the speed is higher it is smoother, and the lower the slower, and now the turn is relative to the middle of the car, but it should be relative to the rear wheels if it turns the front, you need to shift drawRect not to the center of the car, but to rear wheels.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question