protected override void OnUpdate()
    {
        var grenadePresentArray = Group.GetComponentArray <GrenadePresentation>();
        var grenadeClientArray  = Group.GetComponentArray <GrenadeClient>();
        var time = m_world.worldTime;

        for (var i = 0; i < grenadePresentArray.Length; i++)
        {
            var presentation  = grenadePresentArray[i];
            var grenadeClient = grenadeClientArray[i];

            presentation.transform.position = presentation.state.position;

            if (presentation.state.bouncetick > grenadeClient.bounceTick)
            {
                grenadeClient.bounceTick = presentation.state.bouncetick;
                Game.SoundSystem.Play(grenadeClient.bounceSound, presentation.state.position);
            }

            if (presentation.state.exploded && !grenadeClient.exploded)
            {
                grenadeClient.exploded = true;

                grenadeClient.geometry.SetActive(false);

                if (grenadeClient.explodeEffect != null)
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, grenadeClient.explodeEffect, presentation.state.position,
                                                Quaternion.identity);
                }
            }
        }
    }
Example #2
0
    public static void Create(EntityCommandBuffer commandBuffer, SpatialEffectTypeDefinition definition, Vector3 position, Quaternion rotation)
    {
        var request = new SpatialEffectRequest(definition, position, rotation);

        commandBuffer.CreateEntity();
        commandBuffer.AddComponent(request);
    }
Example #3
0
    protected override void Update(Entity entity, DestructablePropReplicatedState replicatedState, DestructiblePropPresentation presentation)
    {
        if (presentation.triggered)
        {
            return;
        }

        if (replicatedState.destroyedTick == 0)
        {
            return;
        }

        foreach (var renderer in presentation.geometryRoot.GetComponentsInChildren <Renderer>())
        {
            renderer.enabled = false;
        }

        presentation.triggered = true;

        foreach (var gameObject in presentation.collision)
        {
            gameObject.SetActive(false);
        }

        // Trigger effect if it just happened (otherwise late joiner will se effect when connecting)
        var time = m_world.worldTime;

        if (time.DurationSinceTick(replicatedState.destroyedTick) < presentation.triggerEffectTimeThreshold)
        {
            for (var i = 0; i < presentation.shatterSettings.rigidBodies.Length; i++)
            {
                var center = presentation.shatterSettings.center.position;
                center.x += UnityEngine.Random.Range(-presentation.shatterSettings.centerRnd, presentation.shatterSettings.centerRnd);
                center.y += UnityEngine.Random.Range(-presentation.shatterSettings.centerRnd, presentation.shatterSettings.centerRnd);
                center.z += UnityEngine.Random.Range(-presentation.shatterSettings.centerRnd, presentation.shatterSettings.centerRnd);

                var rigidBody = presentation.shatterSettings.rigidBodies[i];
                rigidBody.gameObject.SetActive(true);
                rigidBody.AddExplosionForce(presentation.shatterSettings.explosionForce, center,
                                            presentation.shatterSettings.explosionRadius, presentation.shatterSettings.upwardsModifier, presentation.shatterSettings.mode);
            }

            if (presentation.destructionEffect != null)
            {
                SpatialEffectRequest.Create(PostUpdateCommands, presentation.destructionEffect,
                                            presentation.destructionEffectTransform.position, presentation.destructionEffectTransform.rotation);
            }
        }
    }
    protected override void OnUpdate()
    {
        for (int i = 0, c = teleporters.teleporterClients.Length; i < c; i++)
        {
            var teleporterPresentation = teleporters.teleporterPresentations[i];
            var teleporterClient       = teleporters.teleporterClients[i];

            if (teleporterClient.effectEvent.Update(m_GameWorld.worldTime, teleporterPresentation.effectTick))
            {
                if (teleporterClient.effect != null)
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, teleporterClient.effect,
                                                teleporterClient.effectTransform.position, teleporterClient.effectTransform.rotation);
                }
            }
        }
    }
Example #5
0
    public static void Update(GameWorld world, EntityCommandBuffer commandBuffer, ClientProjectile clientProjectile)
    {
        var deltaTime = world.frameDuration;

        if (clientProjectile.impacted)
        {
            return;
        }

        // When projectile disappears we hide clientprojectile
        if (clientProjectile.projectile == Entity.Null)
        {
            clientProjectile.SetVisible(false);
            return;
        }

        var projectileData = world.GetEntityManager().GetComponentData <ProjectileData>(clientProjectile.projectile);
        var aliveDuration  = world.worldTime.DurationSinceTick(projectileData.startTick);

        // Interpolation delay can cause projectiles to be spawned before they should be shown.
        if (aliveDuration < 0)
        {
            return;
        }

        if (!clientProjectile.IsVisible)
        {
            clientProjectile.SetVisible(true);
        }

        var dir = Vector3.Normalize(projectileData.endPos - projectileData.startPos);


        var moveDist = aliveDuration * projectileData.settings.velocity;
        var pos      = (Vector3)projectileData.startPos + dir * moveDist;
        var rot      = Quaternion.LookRotation(dir);

        var worldOffset = Vector3.zero;

        if (clientProjectile.offsetScale > 0.0f)
        {
            clientProjectile.offsetScale -= deltaTime / clientProjectile.offsetScaleDuration;
            worldOffset = rot * clientProjectile.startOffset * clientProjectile.offsetScale;
        }

        if (projectileData.impacted == 1 && !clientProjectile.impacted)
        {
            clientProjectile.impacted = true;

            if (clientProjectile.impactEffect != null)
            {
                SpatialEffectRequest.Create(commandBuffer, clientProjectile.impactEffect,
                                            projectileData.impactPos, Quaternion.LookRotation(projectileData.impactNormal));
            }

            clientProjectile.SetVisible(false);
        }


        clientProjectile.transform.position = pos + worldOffset;

//        Debug.DrawLine(projectileData.startPos, pos, Color.red);
//        DebugDraw.Sphere(clientProjectile.transform.position, 0.2f, Color.red);

        clientProjectile.roll += deltaTime * clientProjectile.rotationSpeed;
        var roll = Quaternion.Euler(0, 0, clientProjectile.roll);

        clientProjectile.transform.rotation = rot * roll;

        if (ProjectileModuleClient.drawDebug.IntValue == 1)
        {
            DebugDraw.Sphere(clientProjectile.transform.position, 0.1f, Color.cyan, 1.0f);
        }
    }
Example #6
0
    void Update(GameTime time, TerraformerWeaponA weapon, Character character)
    {
        // Update using AutoRifle ability state
        var autoRifleAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_AutoRifle.InterpolatedState));

        GameDebug.Assert(autoRifleAbility != Entity.Null, "AbilityController does not own a Ability_AutoRifle ability");
        var autoRifleInterpolatedState = EntityManager.GetComponentData <Ability_AutoRifle.InterpolatedState>(autoRifleAbility);

        if (weapon.primaryFireEvent.Update(time, autoRifleInterpolatedState.fireTick))
        {
            if (weapon.primaryFireSound != null)
            {
                if (weapon.primaryFireSoundHandle.IsValid() && weapon.primaryFireSoundHandle.emitter.playing)
                {
                    Game.SoundSystem.Stop(weapon.primaryFireSoundHandle, 0.05f);
                }
                weapon.primaryFireSoundHandle = Game.SoundSystem.Play(weapon.primaryFireSound, weapon.muzzle);
            }

            if (weapon.primaryFireEffect != null)
            {
                weapon.primaryFireEffect.Play();
            }

            if (weapon.hitscanEffect != null)
            {
                HitscanEffectRequest.Create(PostUpdateCommands, weapon.hitscanEffect, weapon.muzzle.position,
                                            autoRifleInterpolatedState.fireEndPos);
            }

            if (autoRifleInterpolatedState.impactType != Ability_AutoRifle.ImpactType.None)
            {
                var rotation = Quaternion.LookRotation(autoRifleInterpolatedState.impactNormal);
                if (autoRifleInterpolatedState.impactType == Ability_AutoRifle.ImpactType.Character)
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, weapon.characterImpactEffect,
                                                autoRifleInterpolatedState.fireEndPos, rotation);
                }
                else
                {
                    SpatialEffectRequest.Create(PostUpdateCommands, weapon.environmentImpactEffect,
                                                autoRifleInterpolatedState.fireEndPos, rotation);
                }
            }
        }

        // Update using ProjectileLauncher ability state
        var rocketAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_ProjectileLauncher.InterpolatedState));

        GameDebug.Assert(rocketAbility != Entity.Null, "AbilityController does not own a Ability_ProjectileLauncher ability");
        var rocketLaunchInterpolatedState = EntityManager.GetComponentData <Ability_ProjectileLauncher.InterpolatedState>(rocketAbility);

        if (weapon.secondaryFireEvent.Update(time, rocketLaunchInterpolatedState.fireTick))
        {
            if (weapon.secondaryFireSound != null)
            {
                Game.SoundSystem.Play(weapon.secondaryFireSound, weapon.muzzle);
            }

            if (weapon.secondaryFireEffect != null)
            {
                weapon.secondaryFireEffect.Play();
            }
        }

        // Update using Melee ability ability state
        var meleeAbility = character.FindAbilityWithComponent(EntityManager, typeof(Ability_Melee.InterpolatedState));

        GameDebug.Assert(meleeAbility != Entity.Null, "AbilityController does not own a Ability_Melee ability");
        var meleeInterpolatedState = EntityManager.GetComponentData <Ability_Melee.InterpolatedState>(meleeAbility);

        if (weapon.meleeImpactEvent.Update(time, meleeInterpolatedState.impactTick))
        {
            if (weapon.meleeImpactSound != null)
            {
                Game.SoundSystem.Play(weapon.meleeImpactSound, weapon.transform.position);
            }

            if (weapon.meleeImpactEffect != null)
            {
                weapon.meleeImpactEffect.Play();
            }
        }



        // Vents disabled vents until we find out what to do with them
        // Update vents
//            if (entity.vents != null)
//            {
//                for (int ventIndex = 0; ventIndex < entity.vents.Length; ventIndex++)
//                {
//                    if (entity.ventRotationSpeed[ventIndex] == 0)
//                        continue;
//
//                    // Rotate
//                    float deltaRot = entity.ventRotationSpeed[ventIndex] * m_world.frameDuration;
//                    Vector3 eulerRot = entity.vents[ventIndex].rotation.eulerAngles;
//                    eulerRot.z += deltaRot;
//                    entity.vents[ventIndex].rotation = Quaternion.Euler(eulerRot);
//
//                    // Damp speed
//                    float deltaSpeed = entity.ventDampSpeed * m_world.frameDuration;
//                    float absSpeed = Mathf.Abs(entity.ventRotationSpeed[ventIndex]);
//                    if (deltaSpeed >= absSpeed)
//                        entity.ventRotationSpeed[ventIndex] = 0;
//                    else
//                        entity.ventRotationSpeed[ventIndex] -= Mathf.Sign(entity.ventRotationSpeed[ventIndex]) * deltaSpeed;
//                }
//
//                Character.State.Action newAction = weapon.action;
//                if (newAction != entity.m_prevAction)
//                {
//                    if (newAction == Character.State.Action.PrimaryFire)
//                    {
//                        entity.ventRotationSpeed[entity.nextVentIndex] = entity.ventStartSpeed;
//                        entity.ventRotationSpeed[entity.nextVentIndex + 1] = -entity.ventStartSpeed;
//                        entity.nextVentIndex = (entity.nextVentIndex + 2) % entity.vents.Length;
//                    }
//                    if (newAction == Character.State.Action.SecondaryFire)
//                    {
//                        entity.timelineGrenadeRefill.time = 0;
//                        entity.timelineGrenadeRefill.Play();
//                    }
//
//                    entity.m_prevAction = newAction;
//                }
//            }


        // Velocity based ammo fuel angle
        if (weapon.grenadeFuelBase != null)
        {
            Vector3 basePos = weapon.grenadeFuelBase.position;
            Vector3 moveVec = basePos - weapon.m_lastGrenadeFuelWorldPos;
            weapon.m_lastGrenadeFuelWorldPos = basePos;

            Vector3    rotateAxis = Vector3.Cross(moveVec, Vector3.up).normalized;
            float      moveVel    = moveVec.magnitude / m_world.frameDuration;
            float      angle      = moveVel * 2;
            Quaternion targetRot  = Quaternion.AngleAxis(-angle, rotateAxis);

            weapon.grenadeFuelBase.rotation = Quaternion.Lerp(weapon.grenadeFuelBase.rotation, targetRot, 3 * m_world.frameDuration);
        }
    }