引言
实现子弹跟随的游戏开发技巧之3D版本
大家好,在上一篇文章中,笔者介绍了如何在Cocos游戏开发中实现2D子弹的跟随效果。
有许多感兴趣的小伙伴私信我,有没有3D版本的呀?
3D其实和2D的子弹跟随效果大同小异,需要一些简单的数学知识。
于是,本文将介绍一下如何实现3D版本的子弹跟随效果。
本文源工程在文末获取,小伙伴们自行前往。
还是直接上代码
import {
_decorator, CCFloat, Component, instantiate, Node, tween, v3, Vec3 } from 'cc';
const {
ccclass, property } = _decorator;
@ccclass('BulletFollow3D')
export class BulletFollow3D extends Component {
// 属性定义
@property(Node)
target: Node;
@property(Node)
bulletPfb: Node;
@property(Node)
bumpPfb: Node;
@property(CCFloat)
internal: number = 5;
@property(CCFloat)
speed: number