LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Rotate and move

Root / Programming Questions / [.]

Z_E_R_OCreated:
How do I make an animal rotate then move in the direction they're facing?

You can rotate sprites using SPROT.

You can move towards a direction with DX = COS(ANGLE) DY = SIN(ANGLE)

You can move towards a direction with DX = COS(ANGLE) DY = SIN(ANGLE)
Thank you!!!

You can move towards a direction with DX = COS(ANGLE) DY = SIN(ANGLE)
Thank you!!!
How would I turn that into when they rotate, They move that direction.

Well it really depends on the type of sprite, top down ones sometimes dont love being held upside-down, but views from the top sometimes do love it. If I were you, I would bake them some nice cookies and tell them that they will get more if they love that direction.

You can get the current sprite position with SPOFS ID OUT X,Y You can then update the position with SPOFS ID, X+DX, Y+DY

You can get the current sprite position with SPOFS ID OUT X,Y You can then update the position with SPOFS ID, X+DX, Y+DY
I'll try that thank you

To get a sprite to rotate towards a specific random point you'll have to check a conditional and rotate the sprite a certain amount each loop iteration after choosing the final rotational degree. I'm not sure how to make it move in a direction using a degree. Rotational code:
WHILE 1 'Game loop. You can put this in a DEF function (or just paste it) and use it elsewhere.
 IF #A AND BUTTON(3) THEN
  IF R<=0 THEN 'Start a new rotation after the last one completes.
   R=RND(360)
   ROTSPEED=RND(4) 'Optional, use if you want to rotate the sprite at a random speed each time.
   ENDIF
  IF R>0 THEN
   SPROT ID, R
   DEC R,ROTSPEED 'Spacing after punctuation may be a good idea but whatever
   ENDIF
  ENDIF
 VSYNC
 WEND
When you press A, the sprite will rotate randomly. Be sure to set up the necessary sprite(s) and variables.

Thank you