Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
0
Members

Follow Mouse Position not exact?

A topic by jjunker created May 28, 2016 Views: 815 Replies: 3
Viewing posts 1 to 4

I created this script and attached it to an actor:

class FollowMouseBehavior extends Sup.Behavior {

update() {

this.actor.setPosition(Sup.Input.getMousePosition());

}

}

Sup.registerBehavior(FollowMouseBehavior);


It "roughly" follows the mouse cursor, but it drags behind a bit and I'm not sure why.

Mouse dont use normal coordinate.

0 is the center of the screen game

-1 for left, 1 for right

-1 for down, 1 for up


if you want to use pixel coordinate of game screen, you can use :

camera: Sup.Camera;

awake() {
    this.camera = Sup.getActor("Camera").camera;
}

update() {
    let mouse = Sup.Input.getMousePosition().unproject(this.camera);
}

Thanks, that works!

(BTW, how do you format the code block like that?)

Icon "Formating" after "<>" html , and choose code