Discord
Login
Community
DARK THEME

Pointing

I have been trouble finding out how to make the screen.setDrawRotation() To a point in which it points at a sprite in the direction of my mouse. this has bugged me for a while and cannot find any projects in which this is implied. all i am asking is a line of math to make this happen.

thank you.

This is the general function that I use to find the angle between 2 objects:

// finds the angle in degrees from point 1 to point 2
  getAngle = function(x1, y1, x2, y2)
    return atan2d(y2 - y1, x2 - x1)
  end

And then you use it like this: angle = getAngle(pointer.x,pointer.y,mouse.x,mouse.y)

You might have to adjust the angle depending on the default orientation of your 'pointer' sprite (+90, -90, etc.)

In this (non functional) mini project I'm working on I used a clamp function to limit the range to 90degree:

:embed https://microstudio.io/TinkerSmith/powwowpirates/JGYGS3B4/

Thanks Tinker-smith, Very cool! :)

Post a reply

Progress

Status

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