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.

2D All the way! / Help rotating a sprite towards the center of the screen.

Author
Message
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 07:17 Edited at: 27th Apr 2003 07:18
I hate asking for help but, I'm stuck, I've been stuck for awhile on this one.

The player is in the center of the sreen and the map scrolls under him.

All I want to do is when you locate a enemy the sprite for the enemy will rotate towards the player(the center of the screen).

I have tried all kinds of angle maths, no luck. I thought I was close when I broke the screen into four sections so I could figure out where the sprite was in relation to the center of the screen, but alas I never got that to work either.

I've posted the loop that moves the enemy and the part inside of the remstart and remend is the rotation section. All this version does is just have them fly in circles, not my closest attemp but it's what I have at the moment.

Any help is appreiated,
CTP

Stevo
21
Years of Service
User Offline
Joined: 4th Oct 2002
Location:
Posted: 27th Apr 2003 08:41
are you using dbpro? I'm not sure how to make a sprite rotate like this

CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 09:00
wouldn't you know it I figured it out after I asked for help of course.
I had to use atan to figure it out for anybody else trying to figure this out.

good day,
CTP

ps, yes steve it is dbpro.

the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 27th Apr 2003 18:04
atanfull is the command you need.

From the manual

ATANFULL
This command will return the angle of two points in degrees between 0 and 360. The distance values are calculated by finding the distance between two points for both the X and Y axis. The distance values
can be a real or integer number. The return value is a real number.

SYNTAX
Return Float=ATANFULL(Distance X, Distance Y)
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 20:56
heres the code if it helps anyone.
CTP


if sprite angle(99+i) > (180-(90-atan((240-sprite y(99+i))/(320-sprite x(99+i)))))+5 or sprite angle(99+i) < (180-(90-atan((240-sprite y(99+i))/(320-sprite x(99+i)))))-5
rem does it need to turn cw or ccw
ccw = (360 + sprite angle(99+i)) - (180-(90-atan((240-sprite y(99+i))/(320-sprite x(99+i)))))
cw = (360 + (180-(90-atan((240-sprite y(99+i))/(320-sprite x(99+i)))))) - sprite angle(99+i)
if ccw > cw
rem turn ccw
rotate sprite 99+i,sprite angle(99+i)-.5
else
rotate sprite 99+i,sprite angle(99+i)+.5
endif
endif

CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 21:20
winch, thanks that atanfull is a useful command as well, didn't know about that one.

CTP

Stevo
21
Years of Service
User Offline
Joined: 4th Oct 2002
Location:
Posted: 30th Apr 2003 02:41
Can someone explain how to use atanfull, it says -two points for both the x aand y axis, but there is only room for 1 set of values?

Login to post a reply

Server time is: 2024-04-18 22:28:22
Your offset time is: 2024-04-18 22:28:22