Jump to content

View more

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Direction vector

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 cold_heats_.--.   Members   

127
Like
0Likes
Like

Posted 24 July 2012 - 08:39 AM

Me again, with another question.
Suppose I have two sprites on screen, sprite A at position (3,5) sprite B at (8,10).I want sprite B to move towards A with the speed of 1 pixel per second.
So I calculate the direction vector from B to A : dir=B-A=(5,5) . Its length "L" will be sqrt(5*5+5*5)=sqrt(50).
I normalize it dir=(5/L, 5/L).The components will now be : dir =(0.7,0.7) .I multiply each by the speed, but in this case they will stay the same.
I update the new position B(8.7,10.7) but the components will have to be type casted to int when I call SDL_BlitSurface().So going by my logic, sprite B will always stay at the same position.
What am I doing wrong ?

#2 Olof Hedman   Members   

5949
Like
0Likes
Like

Posted 24 July 2012 - 08:48 AM

Will it?
next frame, the values should be (9.4,11.4) and at that point it will have moved.
Unless you for some reason destroy the value when you typecast.

Edited by Olof Hedman, 24 July 2012 - 08:49 AM.


#3 cold_heats_.--.   Members   

127
Like
0Likes
Like

Posted 24 July 2012 - 10:43 AM

Gosh, I feel so stupid. Thanks for enlightening me xD !

#4 Farraj   Members   

152
Like
0Likes
Like

Posted 24 July 2012 - 11:38 AM

lol, I read 2/3 of your post and thought this guy knows what he's talking about. What could be the problem :P

Same answer as the above. Just keep looking, it will move :P

Good luck man :)




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.