Align object to vector using Dgame framework

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 14 03:49:45 PDT 2015


On Tuesday, 14 July 2015 at 00:31:56 UTC, codenstuff wrote:
> 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?

I'm sorry. You should use setRotation() instead, rotate() just 
adds to the rotation.


More information about the Digitalmars-d-learn mailing list