so, to make it simple, let say that every 1 second a rectangle will spawn at a random position, and at random angle too...
i already make some codes to spawn it, but i have no idea how to make the rectangle move forward at its current angle, help ?
move an object forward at its current angle ?
Re: move an object forward at its current angle ?
You can use trigonometic functions, sine and cosine, to calculate X and Y component of a unit vector pointing in that direction. Then you can multiply it by speed and it'll move X fraction of the speed on X axis and Y fraction of the speed on Y axis.
Re: move an object forward at its current angle ?
Code: Select all
rect.x = rect.x + math.cos ( rect.angle ) * rect.speed * dt
rect.y = rect.y - math.sin ( rect.angle ) * rect.speed * dt
Re: move an object forward at its current angle ?
Actually it is that way because English is written left to right and top to down. Also TV monitor refresh is left to right and top to down. So this was an pretty obvious choice. But other system not tied to TV monitors for example Vectrex have the y coordinate the other way round. Maybe that was because it was based on devices that draw graphs.
Re: move an object forward at its current angle ?
Mathematical convention is Y pointing upwards, and all math functions work that way. Note that this also applies to 3d graphics, where Y is also upwards. Only 2d graphics have Y axis inverted by convention.
Re: move an object forward at its current angle ?
Also monitors are basically an dot matrix (with stereo sound). And matrices are indexed from top to down and left to right.
Also computers are used for math only by few people. IBM PC compatibles main usage is:
On the other hand no one keeps you from inverting the y-Axis. (Want your y-Axis inverted of Operation system level basis use OS/2 or MacOS and not Windows or Linux.)
Also computers are used for math only by few people. IBM PC compatibles main usage is:
On the other hand no one keeps you from inverting the y-Axis. (Want your y-Axis inverted of Operation system level basis use OS/2 or MacOS and not Windows or Linux.)
Re: move an object forward at its current angle ?
Which is a shame really. Computers are meant to do calculation-heavy tasks, not help file your paperwork - which only spawned more paperwork ultimately.
Who is online
Users browsing this forum: Google [Bot] and 4 guests