Skip to main content

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

[Script] Drag movement camera

A topic by Neross created Dec 26, 2019 Views: 405 Replies: 1
Viewing posts 1 to 2
(1 edit)

Bonjour à tous,

Voici le code d'un behavior de caméra permettant de la faire ce déplacer grâce a un clic + glisser de la souris.

class CameraBehavior extends Sup.Behavior {
    speed = 0.04
    dragOrigin : Sup.Math.Vector3;
    awake() {
    
  }
  update() {
    let mousePos = Sup.Input.getMousePosition();
    let mousePos3d = new Sup.Math.Vector3(mousePos.x, mousePos.y, 0);
    let cameraPos = this.actor.getPosition();   
    mousePos3d.unproject(this.actor.camera);
    
           if (Sup.Input.wasMouseButtonJustPressed(0))
        {
            this.dragOrigin = mousePos3d;
            return;
        }
 
        if (!Sup.Input.isMouseButtonDown(0)) return;
 
        this.actor.move(mousePos3d.subtract(this.dragOrigin).multiplyScalar(-this.speed));   }
}
Sup.registerBehavior(CameraBehavior); 


J’espère que sa en aidera certain. Je continuerais à partager quelques bouts de codes.

ho, merci  ^^