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.

Newcomers DBPro Corner / mathematical problem

Author
Message
raar
20
Years of Service
User Offline
Joined: 9th Jul 2004
Location:
Posted: 27th Feb 2005 23:49
i want to make a game where yer char is in the middle of the screen and enemy's come form left and right. I want the enemy's to walk toward you so even if they come from the top right they walk towards you, in a diagonal line.
I think this has something to do with cos/sin but i just can't figure out the angle to rotate the sprite and the move it with the move command.
comando 300
21
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 28th Feb 2005 00:27
If you want a diagonal,then increase in x axe and in y axe.

[href]http://www.freewebs.com/comando_300/[/href]
raar
20
Years of Service
User Offline
Joined: 9th Jul 2004
Location:
Posted: 28th Feb 2005 00:59
its only a diagonal if its the top right corner it can be any angle since the enemy's spawn at every y value of the left and right side of the screen
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Feb 2005 05:40
bearing#=atanfull(x2-x1,y2-y1) should do it.


Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Feb 2005 05:47
this small unfinished concept may help you doing what you want..it's planes flying from different directions attacking you..

Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 28th Feb 2005 05:56
Ric's code is perfect but might need a little explanation:

Let x1/y1 be the coordinates of the player, x2/y2 are the coordinates of the enemies. Simply rotate the sprite to bearing# having applied his formula and it will face the right way, provided, and this is important, the sprite is drawn such that when rotated 0 degrees it faces directly right.

Personally I don't really see the point of the atanfull() command - it seems unncessary but there we go. Exactly the same would happen if you used

bearing#=atan((y2-y1)/(x2-x1))

Why do you sink I ave zees outRAGEOUS accente?!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 28th Feb 2005 06:22
Not trying to muddy the waters, but I have a feeling atan will give different results - because its range is -90 to +90, and angles in two out of the four quadrants of a circle will give the same results. Atanfull, on the other hand has a range of -180 to +180, so angles in each quadrant are unique. Could be wrong, though - angles in DBP always do my head in.


Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 28th Feb 2005 06:46
Actually you're probably right - got I hate inverse trig. All that crap having to define domains so it's 1 to 1 and what not, does my head in. You'd need to use a load of if/endifs to make it work using atan so it's probably a lot better to use atanfull. I take it all back.

Why do you sink I ave zees outRAGEOUS accente?!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2005 07:00
use wrapvalue() on the returned angle from atanfull and you shouldn't have any problems.

"eureka" - Archimedes
raar
20
Years of Service
User Offline
Joined: 9th Jul 2004
Location:
Posted: 1st Mar 2005 02:40
thanks though i think i gonna try to make it in 3D so the player will be a cone in the middle and the enemy's ll be some cubes comming at you, so its the same question for 3D :s

Login to post a reply

Server time is: 2024-11-27 23:47:01
Your offset time is: 2024-11-27 23:47:01