Commit 15f74b0d authored by 智慧's avatar 智慧

feat:射线+物理碰撞小测试

parent baca6e06
import RayCastType = cc.RayCastType;
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
//方向
dir: cc.Vec2 = cc.v2(0, 1)
onLoad () {
cc.director.getPhysicsManager().enabled = true;
}
start () {
}
update (dt) {
this.node.x += this.dir.x * 100 * dt;
this.node.y += this.dir.y * 100 * dt;
// 射线检测
let res = cc.director.getPhysicsManager().rayCast(this.node.position, cc.v2(this.node.x, this.node.y + this.dir.y * 100), RayCastType.Closest);
if (res.length > 0) {
this.dir.y *= -1;
}
}
}
{
"ver": "1.0.8",
"uuid": "d1040708-c734-49ca-9bae-d3878f7670da",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
{
"ver": "1.2.9",
"uuid": "142b681b-65cd-4814-8c95-9d6431f5eda1",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment