Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 90285

笔记:3D模型的简单使用

$
0
0

@valiancer 写道:

记录开发过程中的小问题,请多指教
由于是直接从微信文制过来,文章样式格式有点乱·····
完整样式请阅读微信原文
更多笔记和源码请访问公众号

gif中模型的动作:

①游戏状态:待机->奔跑->转向

②指令执行:奔跑->跳跃->死亡

③顺序执行:行走->奔跑->跳跃->死亡

实现

1资源

①拖拽FBX模型到资源管理器

②拖拽模型的预制件到场景中

③添加光源,3D模型只有添加光源后才会显示出来
④拖拽相应的动画文件到SkeletonAnimation组件中

2动作

使用脚本控制动画:
https://docs.cocos.com/creator/manual/zh/animation/scripting-animation.html

声明:

@property(cc.SkeletonAnimation)
model: cc.SkeletonAnimation = null;

监听:

this.model.on('play', this.onPlay, this);
this.model.on('stop', this.onStop, this);
this.model.on('finished', this.onFinished, this);

onPlay(type, state: AnimationState)
{
// console.log(state.name);
}

onStop(type, state: AnimationState)
{
// console.log(state.name);
}

onFinished(type, state: AnimationState)
{
// console.log(state.name);

if (this._sequence) {
if (state.name == "Armature|Walk-Cycle") {
let animationState = this.model.play("Armature|Run-Cycle");
animationState.repeatCount = 1;
} else if (state.name == "Armature|Run-Cycle") {
let animationState = this.model.play("Armature|Jump");
animationState.repeatCount = 1;
} else if (state.name == "Armature|Jump") {
let animationState = this.model.play("Armature|Die_1");

  this._sequence = false;
}

}
}

表演:

let animationState = this.model.play("Armature|Jump");
animationState.repeatCount = 1;

repeatCount:动画播放次数

3转向

模型在移动的时候,需要控制转向

normalizeSelf:向量归一化,让这个向量的长度为 1

signAngle:带方向的夹角的弧度

cc.misc.radiansToDegrees:弧度转角度

target为目标点

let vector = target.sub(this.node.position).normalizeSelf();
let y = 90 - cc.misc.radiansToDegrees(cc.v2(vector).signAngle(cc.v2(1,0)));
this.node.eulerAngles = cc.v3(0, y, 0);

帖子: 3

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 90285

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>