Discord
Login
Community
DARK THEME

How to make a object move towards a location

I did manage to do this but it doesn't work!

https://microstudio.io/Monkeyy/wires/G4M66353/ - Press q and it should move towards the mouse, but it doesn't.

Here's the code:

if keyboard.Q then

plr.x = plr.x + cosd(angle) * 2
plr.y = plr.y + sind(angle) * 2

end

--Note press left click to set the location it should move towards

>> https://microstudio.io/i/Loginus/atan2/ << New Code

The Y axis is inverted in microStudio (for simplicity). You need to reverse the direction (angle) returned by getAngle (atan2) by 180 degrees.

  screen.setRotation( angle ) 
  • rotates the coordinate axis by a given angle. this causes if you used
   screen.drawSprite( name_sprite, player.x, player.y , 40, 40 )

sprite would be in the wrong place. You need to use setTranslation.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community