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! / How do I make one Sprite rotate to face another?

Author
Message
Tone Eternal
20
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 08:00 Edited at: 27th Apr 2003 08:01
I'm REALLY stuck on this one. I cannot figure out the logistics even in my head on how to program this...

I've seen it done so many times in other games, so I know its very possible.. How do I make one sprite turn to face the other?

i.e. : As Object A moves around the screen. Object B is always pointing at it...

Any suggestions? I find this mind-boggling! :-s

Thanks.
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 27th Apr 2003 08:35
Well, if you're using DBPro then what you need is a GetSpriteAngle() function:



...where spr1 is a center sprite and spr2 is a sprite positioned somewhere around the center sprite. The angle returned can be used to set the sprite rotation.

A small demo:
Move the circle with the mouse and the arrow will always point to it.



Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Tone Eternal
20
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 27th Apr 2003 08:47 Edited at: 27th Apr 2003 08:48
Awesome! You Rock!

Thanks a million!
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 21:34
Easily Confused, I was doing the same thing but my routine is a lot more complicated then yours so I'm trying to implement your function, I'm haveing a little problem maybe you can help me.

I want the sprite to turn towards the center of the screen slowly and turn clockwise or counter clockwise( which ever is shorter).

in this snippet it works fine until the angle towards the center crosses the 0/359 axis. I know I need to flipflop it here but I'm a little stuck.

Would you be so kind as to take a look?
thanks,
CTP




Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 27th Apr 2003 22:24 Edited at: 27th Apr 2003 22:44
If I'm interpreting your problem correctly, you may need the CurveAngle() command here.



Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 27th Apr 2003 23:08
Hey thats nice, thanks alot, another command I didn't know how to use!

I'm learning alot on this project.

Thanks,
CTP

CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 28th Apr 2003 02:10
well I had a little trouble with that curve angle command seams I was getting some eratic response in my game, but I got my 1st snippet to work after I figured out how to calculate the distance in dregrees around the circle.
where it loop around the 0/359 dregree point I just had to offset the value by 360 to figure the distance.

Heres the snippet and thanks to Easily Confused for the GetSpriteAngle function that eliminated atleast 20 lines of code in my program.



Login to post a reply

Server time is: 2024-03-29 12:10:20
Your offset time is: 2024-03-29 12:10:20