public GameObject CreateBullet(GameObject nozzle) { Vector3 vel = new OpenTK.Vector3(-OpenTK.Vector4.UnitZ * nozzle.GetWorldTransform()) * BulletLaunchForce; OpenTK.Vector3 v = vel; GameObject bullet = new GameObject(nozzle.LocalPosition + (Vector3)v.Normalized(), "BulletEnemy"); bullet.Rotation = nozzle.Rotation; bullet.AddComponent(new LitMeshRendererComponent(BulletShader, BulletModel, BulletTexture, 1, false)); bullet.AddComponent(new DestroyTimer(5)); bullet.Scale = new Vector3(0.3f, 0.3f, 1); Collider coll = new Collider(new Box(Vector3.Zero, 0.3f, 0.3f, 1, BulletMass), LayerManager.NameToLayer("physics")); if (!PhysicalBullets) { coll.IsTrigger = true; } bullet.AddComponent(coll); coll.PhysicsCollider.ApplyLinearImpulse(ref vel); return(bullet); }
public ParticleDigging(World world, Vector3 pos, Vector3 motion, float particleScale, BlockState state, FaceSides side) : base(world, pos, motion, particleScale, JsonModelLoader.TEXTURE_BLOCKS) { State = state; ModelBlock model = JsonModelLoader.GetModelForBlock(state.Block.UnlocalizedName); if (model.RawModel is ModelBlockRaw mbr) { Vector2 start; Vector2 end; if (state.Block.IsFullCube) { List <float> uvs = new List <float>(8); mbr.AppendUvsForSide(side, uvs); start = new Vector2(uvs[0], uvs[1]); end = new Vector2(uvs[4], uvs[5]); //4,5 because that's the 3. vertex and the local UV there is 1,1 } else { var tex = model.GetParticleTexture(); start = tex.UVMin; end = tex.UVMax; } Vector2 size = end - start; Vector2 pixel = size / 16; UVmin = start + pixel * new Vector2(MathUtil.NextFloat(0, 12), MathUtil.NextFloat(0, 12)); UVmax = UVmin + pixel * 4; } if (side == FaceSides.Up) { Motion.Xz = SharpCraft.Instance.Camera.GetLookVec().Xz * 0.15f; } Vector3 vec = new Vector3(MathUtil.NextFloat(-1), MathUtil.NextFloat(-1), MathUtil.NextFloat(-1)); _rotStep = vec.Normalized() * MathUtil.NextFloat(40, 75); }