当前位置:网站首页>Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
2022-08-03 08:08:00 【charlsdm】
下边附上摄像机跟随人物移动,点击人物之后触发事件的Demo
下边附加上Ts的CameraFollow脚本
export default class CameraFollow extends Laya.Script {
private CameraGameObj:Laya.Sprite3D;
private target:Laya.Sprite3D;
public angle:number=30;
public distance:number=25;
public dis:Laya.Vector3=new Laya.Vector3();
private point:Laya.Vector2=new Laya.Vector2();
private camera:Laya.Camera;
private scene:Laya.Scene3D;
private ray:Laya.Ray;
private outHitResult:Laya.HitResult;
constructor() {
super();
console.log("CameraFollowScript开始");
}
public InitMySelfGameObj(scene:Laya.Scene3D,camera:Laya.Camera):void{
this.CameraGameObj=scene.getChildAt(0) as Laya.Sprite3D;
console.log("thisCameraObj:"+this.CameraGameObj.name);
this.target=scene.getChildAt(3) as Laya.Sprite3D;
console.log("thisTargetObj:"+this.target.name);
this.dis.x=this.target.transform.position.x-this.CameraGameObj.transform.position.x;
this.dis.y=this.target.transform.position.y-this.CameraGameObj.transform.position.y;
this.dis.z=this.target.transform.position.z-this.CameraGameObj.transform.position.z;
this.camera=camera;
this.scene=scene;
this.ray=new Laya.Ray(new Laya.Vector3(0,0,0),new Laya.Vector3(0,0,0));
this.outHitResult=new Laya.HitResult();
// Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.onMouseDown)
}
onMouseDown()
{
this.point.x = Laya.MouseManager.instance.mouseX;
this.point.y = Laya.MouseManager.instance.mouseY;
this.camera.viewportPointToRay(this.point, this.ray);
this.scene.physicsSimulation.rayCast(this.ray,this.outHitResult);
//如果碰撞到物体
if (this.outHitResult.succeeded)
{
//删除碰撞到的物体
this.target.transform.position=new Laya.Vector3(0,20,0);
console.log("碰撞到物体!!")
}
}
onUpdate():void
{
}
onLateUpdate():void
{
let nowPos:Laya.Vector3=new Laya.Vector3();
nowPos.x=this.target.transform.position.x-this.dis.x;
nowPos.y=this.target.transform.position.y-this.dis.y;
nowPos.z=this.target.transform.position.z-this.dis.z;
this.CameraGameObj.transform.position=nowPos;
}
}
边栏推荐
猜你喜欢
随机推荐
Eject stubborn hard drives with diskpart's offline command
Logic Pro X自带音色库列表
使用pipreqs导出项目所需的requirements.txt(而非整个环境)
推荐系统-排序层-模型:Wide&Deep
Karatsuba大数乘法的Verilog实现
Redis的基础与django使用redis
mysql备份时的快照原理
并发之多把锁和活跃性
服务器资源监控工具-nmon、nmon_analyser
如何在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster?
内存模型之有序性
Pyspark - an empty string is replaced by None
品牌方发行NFT时,应如何考量实用性?
LAN技术-2免费ARP
学习笔记:机器学习之逻辑回归
并发之固定运行和交替运行方案
千万级别的表分页查询非常慢,怎么办?
mysql系统变量与状态变量
解决移动端有纵向滚动条但是不能滚动的问题
Charles抓包工具学习记录