import Vector3 = Laya.Vector3;
import Sprite3D = Laya.Sprite3D;
export class Runner extends Laya.Script3D{
    private static ins:Runner;
    m_player:Sprite3D;
    constructor(){
        super();
    }
    public static get Instance():Runner{
        if(Runner.ins){
            return Runner.ins
        }
        else{
            return new Runner();
        }
    }
    onAwake(){
        this.m_player = this.owner as Sprite3D;
    }
    onUpdate(){

    }
    MoveX(_speed:number){
        _speed*=0.07;

        //var dir = new Vector3(_speed,0,0);
        //Vector3.add(this.m_sprite.transform.position,dir,this.m_sprite.transform.position);
        this.m_player.transform.translate(new Vector3(_speed,0,0));

        this.m_player.transform.position = this.m_player.transform.position.x < -4.5?new Vector3(-4.5,this.m_player.transform.position.y,this.m_player.transform.position.z):this.m_player.transform.position;
        this.m_player.transform.position = this.m_player.transform.position.x > 4.5?new Vector3(4.5,this.m_player.transform.position.y,this.m_player.transform.position.z):this.m_player.transform.position;
        //this.m_sprite.transform.position = this.curpos;
    }
    currotV = new Vector3();
    currot = new Laya.Quaternion;
    NormalizeSpeed:Vector3 = new Vector3();
    turndir:Vector3 = new Vector3(1,0,0);
    TurnDir(_dir:Vector3)
    {
        if(_dir.x != 0)
        {
            Vector3.lerp(this.currotV,_dir,0.35,_dir);
            this.currotV = _dir;
            Laya.Quaternion.rotationLookAt(_dir,new Vector3(0,1,0),this.currot);
            Laya.Quaternion.slerp(this.m_player.transform.rotation,this.currot,0.025,this.currot);
            this.currot = new Laya.Quaternion(0,this.currot.y,0);
            this.m_player.transform.rotation = this.currot;
        }
        else
        {
            Laya.Quaternion.slerp(this.m_player.transform.rotation,new Laya.Quaternion(0,0,0,0),0.1,this.currot);
            this.currot = new Laya.Quaternion(0,this.currot.y,0);
            this.m_player.transform.rotation = this.currot;
        }
    }
}