Align object to vector using Dgame framework

codenstuff via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 13 17:31:55 PDT 2015


On Monday, 13 July 2015 at 19:07:55 UTC, Márcio Martins wrote:
> On Monday, 13 July 2015 at 16:11:03 UTC, codenstuff wrote:
>> [...]
>
> This is not really a game development forum but here you go:
> auto rads = atan2(object.velocity.y, object.velocity.x); // 
> returns radians
> auto degs = angle * (180.0f / PI); // convert to degrees
> shape.rotate(degs);
>
> I suggest you store velocity as a Vector2f to avoid later 
> confusion.
>
> It is really useful to learn basic linear algebra, and 
> trigonometry as a game developer - you will be needing these 
> tools on a daily basis.

This does not work as expected. It keeps rotating object as long 
as vector is at angle. Any idea how to improve on this?


More information about the Digitalmars-d-learn mailing list