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.

AppGameKit Classic Chat / please help moving sprite

Author
Message
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 10th Jan 2013 18:22
I'm having another problem. I have been able to figure out how to get the enemy to rotate and face the direction the player is.
But i'm having trouble working out how to make the enemy follow the player or move toward the player like a magnet if the player is within range.

http://www.youtube.com/watch?v=Oih6eJtExJY


if GetSpriteExists ( 500 )
spriteraycast ( getspritexByOffset ( 1 ), getspriteyByOffset ( 1 ), getspritexByOffset ( 500 ), getspriteyByOffset ( 500 ) )
rem Angle enemy to point at player
xoffset# = GetRayCastX() - GetSpriteXByOffset ( 500 )
yoffset# = GetRayCastY() - GetSpriteYByOffset ( 500 )

rem Adjustment for angles outside -90 to +90
if xoffset# < 0
bias = 180
else
bias = 0
endif

enemyangle# = atan ( yoffset#/xoffset# ) + bias
SetSpriteAngle ( 500, enemyangle# -90 )
endif
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jan 2013 21:32 Edited at: 10th Jan 2013 21:34
Exploding zombies, classic

Point sprite code:


Move sprite code:


Move sprite up:


The main issue here I think was it helps to use the atanfull command rather than atan.


this.mess = abs(sin(times#))
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 11th Jan 2013 03:42
Thank you so much that work's great.

Login to post a reply

Server time is: 2024-05-03 20:00:53
Your offset time is: 2024-05-03 20:00:53