Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Move in Direction

Author
Message
Kaz3
15
Years of Service
User Offline
Joined: 15th Sep 2009
Location: New York
Posted: 29th Sep 2009 05:08
Using DarkGDK

So I've created a function to find an angle between two points, that works since my sprite points in the correct direction(my mouse). My problem is getting sprites to move in the direction they are facing(a bullet).

I found some material on this forum and it works, to a degree. I've modified it for my own purposes.

functions.cpp


player.cpp


As I said, it works to a degree. The bullet fires in the general direction of the mouse, but seems to round the angle. I've included a picture of what I am saying, the black circle is where my mouse was at the time of firing and the red dot is the bullet. The player's direction and the bullet's direction are the same upon firing and both are doubles.

Attachments

Login to view attachments
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 29th Sep 2009 14:17
Does dbMoveSprite() not move it in the direction it is facing?
Kaz3
15
Years of Service
User Offline
Joined: 15th Sep 2009
Location: New York
Posted: 29th Sep 2009 20:31
Hm, didn't know that function existed. That is solved.

But what is wrong with my functions? Although this is fixed, these functions are very useful(I have used variations in other languages) and I would like to have them working if I ever need them in the future.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 30th Sep 2009 00:27
Were you inputting the direction in radians rather than degrees? The function is setup to take degrees as an input.

Kaz3
15
Years of Service
User Offline
Joined: 15th Sep 2009
Location: New York
Posted: 30th Sep 2009 00:49
Well direction is based on this function:


And that returns degrees.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 30th Sep 2009 03:16
Perhaps it has to do with the origin of the window. What are you inputing for x2 and y2? The functions themselves look as though they should work correctly.

Kaz3
15
Years of Service
User Offline
Joined: 15th Sep 2009
Location: New York
Posted: 30th Sep 2009 04:04


The -90 is because I drew it facing 90 in DGDK, so it reverses that.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 30th Sep 2009 05:34
Well, that's puzzling... I have never used sprites in darkGDK, but are they marked by their center or their upper left hand corner? You may need to add offset values to the sprite coordinates to get the true coordinate of things like the center location for the bullet and the origin.

Kaz3
15
Years of Service
User Offline
Joined: 15th Sep 2009
Location: New York
Posted: 30th Sep 2009 05:50
They are marked by the top-left, but seeing as how the bullet was only 3x3, I don't think it would affect the angle that much or at all.

The player sprite does have a centered offset.

Login to post a reply

Server time is: 2024-11-25 00:18:17
Your offset time is: 2024-11-25 00:18:17