用户:
YDS尹子查看:13 回复:17 评论:13 创建时间:2020-08-26T19:49:58
这可能是我这个暑假分享的最后一个代码了
长按实体即连续发射子弹
https://box3create.codemao.cn/games/e42c8喵9d1af51d777ab
测试处↑
nc=n c
world.onPlayerJoin(({entity})=>{
entity.enableDamage=true;
// entity.player.canFly = 1
entity.hp = entity.maxHp = 1000;
entity.hurtSound="";
})
world.onPress(async({entity,button,pressed,raycast:{hitEntity,direction}})=>{
if(button=="action0"&&pressed){
entity.release=true;
while(entity.release){
hitEntity.hurt(8+Math.random()*4);
entity.sound("audio/land.mp3",5);
entity.sound("audio/land.mp3",5);
await sleep(70);
}
}
})
world.onRelease(({entity})=>{
entity.release=false;
})
迷失冷光发射实体子弹独家秘方,未经允许不得转载。
world.onPlayerJoin(({entity})=>{
entity.position.set(53,3,123);
entity.player.scale = 0.4;
entity.player.runSpeed = 0.2;
entity.player.walkSpeed = 0.12;
entity.player.jumpPower = 0.5;
entity.player.enableDoubleJump = false;
entity.enableDamage = true;
profession(entity);
entity.player.onPress(async({button,raycast:{hitPosition}})=>{
console.log(hitPosition);
if(button == 'action0'){
entity.player.enableShoot = true;
while(entity.player.enableShoot){
await sleep(200);
//raycast.
world.sound('audio/10828.mp3')
biu(entity,hitPosition);
}
}
})
entity.player.onRelease(({button})=>{
if(button == 'action0'){
entity.player.enableShoot = false;
}
})
})
async function biu(attacker, target){
bullet = world.createEntity({
mesh: 'mesh/球形炮弹.vb',
position: attacker.position,
collides: false,
fixed: true,
meshScale: new Box3Vector3(0.002,0.002,0.002),
meshOrientation: attacker.meshOrientation,
})
bullet.shooter = attacker;
bullet.addTag('bullet');
bullet.gravity = false;
bullet.Cx =0;
bullet.Cy =0;
bullet.Cz =0;
bullet.startPos = copy(attacker.position);
bullet.distance = 0;
bullet.speed = 2;
子弹实体化还原(200,bullet);
function init (A, B) {
var dx = B.x -A.x;
var dy = B.y -A.y;
var dz = B.z -A.z;
AB = Math.sqrt(dx*dx + dy*dy + dz*dz);
if (AB==0)
return;
bullet.Cx = dx /AB;
bullet.Cy = dy /AB;
bullet.Cz = dz /AB;
}
init(attacker.position, target);
bullet.onEntityContact(({other})=>{
other.hurt(5);
other.killer = bullet.shooter;
bullet.destroy();
})
}
function updatePos(bullet){
bullet.distance+=bullet.speed;
bullet.speed *=.99;
bullet.position = new Box3Vector3(
bullet.distance *bullet.Cx + bullet.startPos.x,
bullet.distance *bullet.Cy + bullet.startPos.y - bullet.distance*.01,
bullet.distance *bullet.Cz + bullet.startPos.z
)
if(voxels.getVoxel(bullet.position.x,bullet.position.y,bullet.position.z)!=voxels.id('air')){
bullet.destroy();
}
if(bullet.speed <0.2){
bullet.destroy();
return;
}
}
async function 子弹实体化还原(time,bullet){
await sleep(time);
bullet.collides = true;
}
world.onTick(()=>{
world.querySelectorAll('.bullet').forEach((bullet)=>{
updatePos(bullet);
})
})点赞13
评论
YDS尹子实体炮弹代码(简洁版)
world.onPlayerJoin(({entity})=>{
entity.a喵Tag(entity.player.name);
entity.enableDamage=true;
})
world.onPress(async({entity,button})=>{
if(button=="action0"){
var f=3;
a=world.createEntity();
a.mesh=world.querySelector(".pd").mesh;
a.meshScale=world.querySelector(".pd").meshScale;
a.a喵Tag("bullet");
a.owner=entity.player.name;
a.position.set(entity.position.x,entity.position.y+1.5,entity.position.z);
a.collides=true;
a.restitution=1;
a.fixed=false;
a.gravity=true;
var angx=Math.asin(entity.player.facingDirection.x)*180/Math.PI;
var angz=Math.acos(entity.player.facingDirection.z)*180/Math.PI;
a.velocity.x=f*Math.sin(angx*Math.PI/180);
a.velocity.z=f*Math.cos(angz*Math.PI/180);
a.velocity.y=0.3;
setTimeout(()=>{
a.destroy();
},2000)
}
})点赞1
评论