public virtual void DoRotation(Rotation idealRotation) { // // Our ideal player model rotation is the way we're facing // var allowYawDiff = Player.ActiveChild == null ? 120 : 50; float turnSpeed = 0.01f; if (HasTag("ducked")) { turnSpeed = 0.1f; } // // If we're moving, rotate to our ideal rotation // Rot = Rotation.Slerp(Rot, idealRotation, WishVelocity.Length * Time.Delta * turnSpeed); // // Clamp the foot rotation to within 120 degrees of the ideal rotation // Rot = Rot.Clamp(idealRotation, allowYawDiff, out var change); // // If we did restrict, and are standing still, add a foot shuffle // if (change > 1 && WishVelocity.Length <= 1) { TimeSinceFootShuffle = 0; } SetParam("b_shuffle", TimeSinceFootShuffle < 0.1); }
public override void BuildInput(InputBuilder input) { base.BuildInput(input); var pawn = Local.Pawn; if (pawn == null) { return; } if ((Math.Abs(input.AnalogLook.pitch) + Math.Abs(input.AnalogLook.yaw)) > 0.0f) { if (!orbitEnabled) { orbitAngles = (orbitYawRot * orbitPitchRot).Angles(); orbitAngles = orbitAngles.Normal; orbitYawRot = Rotation.From(0.0f, orbitAngles.yaw, 0.0f); orbitPitchRot = Rotation.From(orbitAngles.pitch, 0.0f, 0.0f); } orbitEnabled = true; timeSinceOrbit = 0.0f; orbitAngles.yaw += input.AnalogLook.yaw; orbitAngles.pitch += input.AnalogLook.pitch; orbitAngles = orbitAngles.Normal; orbitAngles.pitch = orbitAngles.pitch.Clamp(MinOrbitPitch, MaxOrbitPitch); } input.ViewAngles = orbitEnabled ? orbitAngles : Entity.Rotation.Angles(); input.ViewAngles = input.ViewAngles.Normal; }
private async Task StartCountdown() { while (Info.Owner != null) { try { LastCountdown = 0f; await GameTask.DelaySeconds(Countdown); if (Info.Owner != null) { OnCountdown(); } } catch (Exception e) { if (e.Message.Trim() == "A task was canceled.") { return; } Log.Error($"[TASK] {e.Message}: {e.StackTrace}"); } } }
public override void Spawn() { SetModel("models/tank_rocket.vmdl"); timeSinceLaunched = 0; Transmit = TransmitType.Always; Tags.Add("rocket"); using (Prediction.Off()) { TrailEffect = Particles.Create("particles/rocket_trail.vpcf"); TrailEffect.SetEntity(0, this, CollisionBounds.Mins.WithZ(0).WithY(0)); } Light = new SpotLightEntity { Position = Position + Rotation.Forward * (CollisionBounds.Mins.x - 1), Rotation = Rotation.LookAt(Rotation.Backward), DynamicShadows = true, Color = new(1, 0.5f, 0), Brightness = 2, Parent = this, Range = 96, InnerConeAngle = 15, OuterConeAngle = 70 }; //timeAlive = Rand.Float(); }
public override void Simulate(Client cl) { //if ( cl.NetworkIdent == 1 ) // return; base.Simulate(cl); // // Input requested a weapon switch // if (Input.ActiveChild != null) { ActiveChild = Input.ActiveChild; } if (LifeState != LifeState.Alive) { return; } TickPlayerUse(); if (Input.Pressed(InputButton.View)) { if (Camera is ThirdPersonCamera) { Camera = new FirstPersonCamera(); } else { Camera = new ThirdPersonCamera(); } } if (Input.Pressed(InputButton.Drop)) { var dropped = Inventory.DropActive(); if (dropped != null) { if (dropped.PhysicsGroup != null) { dropped.PhysicsGroup.Velocity = Velocity + (EyeRot.Forward + EyeRot.Up) * 300; } timeSinceDropped = 0; SwitchToBestWeapon(); } } SimulateActiveChild(cl, ActiveChild); // // If the current weapon is out of ammo and we last fired it over half a second ago // lets try to switch to a better wepaon // if (ActiveChild is BaseDmWeapon weapon && !weapon.IsUsable() && weapon.TimeSincePrimaryAttack > 0.5f && weapon.TimeSinceSecondaryAttack > 0.5f) { SwitchToBestWeapon(); } }
private void Kick() { if (this.timeSinceLastKicked > 0.5f && Input.GetKeyDown(KeyCode.Space)) { kickEffect.Play(); kickParticles.Play(); CameraController.instance.Shake(0.05f, 0.5f); this.timeSinceLastKicked = 0; Collider[] hitColliders = Physics.OverlapSphere(transform.forward * 0.1f + transform.position, 3); for (int i = 0; i < hitColliders.Length; i++) { Collider collider = hitColliders[i]; Vector3 direction = (collider.transform.position - transform.position).normalized; if (Vector3.Dot(direction, transform.forward) > 0.5) { Enemy enemy = collider.GetComponent <Enemy>(); Rigidbody rigidbody = collider.GetComponent <Rigidbody>(); float multiplier = UnityEngine.Random.Range(300, 450); Vector3 force = direction * multiplier + transform.forward * multiplier + transform.up * 150; if (enemy != null) { enemy.Launch(force, 2); } else if (rigidbody != null) { rigidbody.AddForce(force); } } } } }
public override void OnKilled(HitInfo info) { DismountAllPlayers(); foreach (BaseVehicleModule attachedModuleEntity in base.AttachedModuleEntities) { attachedModuleEntity.repair.enabled = false; } if (carLock != null) { carLock.RemoveLock(); } timeSinceDeath = 0f; if (vehicle.carwrecks) { if (!base.HasAnyModules) { Kill(DestroyMode.Gib); } else { SendNetworkUpdate(); } } else { Kill(DestroyMode.Gib); } }
/* Hit by bullet thing */ void OnParticleCollision(GameObject other) { // TODO: balance health loss per particle hit against particle amount if (this.timeSinceHit < InvulTime) { return; } this.timeSinceHit = 0; this.Health--; Debug.Log("Taking HP " + this.Health); if (this.Health < 0) { Debug.Log("DED"); ParticleSystem swirl = Instantiate <ParticleSystem>(deathEffect); swirl.transform.position = gameObject.transform.position; swirl.transform.localScale = Vector3.one * 5; swirl.transform.parent = this.transform; // swirl.Play(); Destroy(swirl, swirl.main.duration); if (alive) { this.Kill(after: swirl.main.duration); } } Vector3 shotDirection = (this.transform.position - other.transform.position).normalized * 100; this.Launch(shotDirection, 0.1f); // TODO magic numbers are fun }
public override void OnPlayerControlTick(Player owner) { if (owner == null) { return; } var input = owner.Input; bool toggle = input.Pressed(InputButton.Flashlight) || input.Pressed(InputButton.Attack1); if (timeSinceLightToggled > 0.1f && toggle) { LightEnabled = !LightEnabled; PlaySound(LightEnabled ? "flashlight-on" : "flashlight-off"); if (worldLight.IsValid()) { worldLight.Enabled = LightEnabled; } if (viewLight.IsValid()) { viewLight.Enabled = LightEnabled; } timeSinceLightToggled = 0; } if (IsClient && input.Pressed(InputButton.Attack2)) { ViewModelEntity?.SetAnimParam("admire", true); } }
public override void Simulate(Client cl) { if (cl == null) { return; } var input = Input; bool toggle = input.Pressed(InputButton.Flashlight) || input.Pressed(InputButton.Attack1); if (timeSinceLightToggled > 0.1f && toggle) { LightEnabled = !LightEnabled; PlaySound(LightEnabled ? "flashlight-on" : "flashlight-off"); if (worldLight.IsValid()) { worldLight.Enabled = LightEnabled; } if (viewLight.IsValid()) { viewLight.Enabled = LightEnabled; } timeSinceLightToggled = 0; } if (IsClient && input.Pressed(InputButton.Attack2)) { ViewModelEntity?.SetAnimBool("admire", true); } }
public void MakeInvincible(float duration) { timeSinceInvincible = 0; invincibilityTime = duration; isInvincible = true; InvincibilityBubble.SetActive(true); }
public override void Simulate() { if (Host.IsServer) { if (Input.Pressed(InputButton.Reload)) { var tr = Trace.Ray(Owner.EyePosition, Owner.EyePosition + Owner.EyeRotation.Forward * 4000).Ignore(Owner).Run(); if (tr.Entity is ModelEntity ent && !string.IsNullOrEmpty(ent.GetModelName())) { modelToShoot = ent.GetModelName(); Log.Trace($"Shooting model: {modelToShoot}"); } } if (Input.Pressed(InputButton.Attack1)) { ShootBox(); } if (Input.Down(InputButton.Attack2) && timeSinceShoot > 0.05f) { timeSinceShoot = 0; ShootBox(); } } }
protected override void Tick() { base.Tick(); if (Input.Pressed(InputButton.Slot1)) { Inventory.SetActiveSlot(0, true); } if (Input.Pressed(InputButton.Slot2)) { Inventory.SetActiveSlot(1, true); } if (Input.Pressed(InputButton.Slot3)) { Inventory.SetActiveSlot(2, true); } if (Input.Pressed(InputButton.Slot4)) { Inventory.SetActiveSlot(3, true); } if (Input.Pressed(InputButton.Slot5)) { Inventory.SetActiveSlot(4, true); } if (Input.Pressed(InputButton.Slot6)) { Inventory.SetActiveSlot(5, true); } if (Input.MouseWheel != 0) { Inventory.SwitchActiveSlot(Input.MouseWheel, true); } if (LifeState != LifeState.Alive) { return; } if (Input.Pressed(InputButton.View)) { if (Camera is ThirdPersonCamera) { Camera = new FirstPersonCamera(); } else { Camera = new ThirdPersonCamera(); } } if (Input.Pressed(InputButton.Drop)) { var dropped = Inventory.DropActive(); if (dropped != null) { timeSinceDropped = 0; } } }
public override void Simulate(Client cl) { if (cl == null) { return; } base.Simulate(cl); bool toggle = Input.Pressed(InputButton.Flashlight) || Input.Pressed(InputButton.Attack1); if (timeSinceLightToggled > 0.1f && toggle) { LightEnabled = !LightEnabled; PlaySound(LightEnabled ? "flashlight-on" : "flashlight-off"); if (worldLight.IsValid()) { worldLight.Enabled = LightEnabled; } if (viewLight.IsValid()) { viewLight.Enabled = LightEnabled; } timeSinceLightToggled = 0; } }
private void CrossFadeClip(AudioClip clip, float volume) { if (_secondarySource == null) { CreateSecondarySource(); // we're probably coming from not being a cross fader _primarySource.GetCallback().OnStop.RemoveListener(OnSourceStop); } AudioSource fadeOutSource; AudioSource fadeInSource; if (_currentSource == _primarySource && _currentSource.isPlaying) { fadeOutSource = _primarySource; fadeInSource = _secondarySource; } else { fadeOutSource = _secondarySource; fadeInSource = _primarySource; } fadeOutSource.FadeOut(CrossFadeDuration); fadeInSource.clip = clip; fadeInSource.FadeIn(CrossFadeDuration, volume); _currentSource = fadeInSource; _timeUntilFade = -FindTimeUntilFade(clip); }
void Start() { anim = GetComponent <Animator> (); if (loadingBay) { bayPos = loadingBay.position; } if (warehouse) { warehousePos = warehouse.position; } float travelDistance = Vector3.Distance(warehousePos, bayPos); freq = speed / Mathf.Max(0.0001f, travelDistance); Vector2 diff = warehousePos - bayPos; float angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg - 90; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); isMoving = false; isDelivering = false; cargoAmt = 0; ts = 0; StartDelivery(); }
void StopTruck() { t = (dir + 1) / 2; transform.position = Vector3.Lerp(bayPos, warehousePos, t); isMoving = false; ts = 0; }
public bool Fire() { Cooldown = _movement.IsAIControlled ? _upgrades.GetEnemySettings().WeaponCooldown : _upgrades.WeaponCooldown; if (!CanFire) { return(false); } if (WeaponAnimator != null && WeaponAnimator.HasParamter("Cooldown")) { WeaponAnimator.SetFloat("Cooldown", 1 / Cooldown); } _timeSinceFired = 0; var projectile = Instantiate(Projectile, FirePoint.position, Quaternion.identity).GetComponent <WeaponProjectile>(); var dir = 0f; if (Mathf.Approximately(_movement.InputDirection, 0)) { dir = _movement.IsFlipped ? -1f : 1f; } else { dir = _movement.InputDirection; } projectile.Fire(_rb.velocity.x, dir, _movement.IsAIControlled); if (WeaponAnimator != null && WeaponAnimator.HasParamter("Cooldown")) { WeaponAnimator.SetTrigger("Fired"); } return(true); }
public override void Spawn() { EnableDrawing = false; PhysicsEnabled = false; timeSinceSpawned = 0; _ = startEmitting(); _ = pulseIndicator(); }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.HasComponent <CharacterControl>()) { other.gameObject.Damage(1); _timeSinceDamagedPlayer = 0f; } }
// Update is called once per frame void Update() { if (ts >= CooldownTime && Input.GetAxis("Fire1") > 0) { Shoot(); ts = 0; } }
public void Fire(Vector2 direction) { if (CanFire()) { TimeSinceFire = 0; Fire_Implementation(direction); } }
public void OnHit(Vector3 pos, float amount) { timeSinceHit = 0; var p = new HitPoint(amount, pos); p.Parent = this; }
public override void Simulate(Client cl) { base.Simulate(cl); if (Input.ActiveChild != null) { Log.Info($"Input.ActiveChild: {Input.ActiveChild}"); ActiveChild = Input.ActiveChild; } if (LifeState != LifeState.Alive) { return; } TickPlayerUse(); SimulateActiveChild(cl, ActiveChild); if (Input.Pressed(InputButton.View)) { if (Camera is not FirstPersonCamera) { Camera = new FirstPersonCamera(); } else { Camera = new ThirdPersonCamera(); } } if (Input.Pressed(InputButton.Drop)) { var dropped = Inventory.DropActive(); if (dropped != null) { dropped.PhysicsGroup.ApplyImpulse(Velocity + EyeRot.Forward * 500.0f + Vector3.Up * 100.0f, true); dropped.PhysicsGroup.ApplyAngularImpulse(Vector3.Random * 100.0f, true); timeSinceDropped = 0; } } if (Input.Released(InputButton.Jump)) { if (timeSinceJumpReleased < 0.3f) { Game.Current?.DoPlayerNoclip(cl); } timeSinceJumpReleased = 0; } if (Input.Left != 0 || Input.Forward != 0) { timeSinceJumpReleased = 1; } }
private void Start() { audioSource = GetComponent <AudioSource>(); spentAmmoSpawner = GetComponentInChildren <SpentAmmoSpawner>(); muzzleFlash = GetComponentInChildren <ParticleSystem>(); shotsRemaining = weaponInfo.startingAmmo; shotTimer = 100; shotsSpent = 0; }
protected virtual void Start() { _timeSinceSpawned = 0f; if (DespawnType == DespawnType.TimeoutRange) { DespawnTimeout = Random.Range(DespawnTimeoutMinimum, DespawnTimeoutMaximum); } }
private void Awake() { _movement = GetComponent <Movement>(); _weapon = GetComponent <Weapon>(); _player = GameObject.FindWithTag("Player"); _playerMovement = _player.GetComponent <Movement>(); _upgrades = ProgressionSystem.Instance; _timeSinceFired = 0f; }
public void RPC_WantsPush(RPCMessage msg) { BasePlayer player = msg.player; if (!player.isMounted && !RecentlyPushed && CanPushNow(player) && (!OnlyOwnerAccessible() || !(player != creatorEntity)) && Interface.CallHook("OnVehiclePush", this, msg.player) == null) { DoPushAction(player); timeSinceLastPush = 0f; } }
public void Update() { if (_timeSinceDamage < 1) { return; } _timeSinceDamage = 0; HealthComponent.Damage(DamagePerSecond); }
private void Taunt(string path = null) { if (path == null) { path = Rand.FromArray(Config.Taunts.ToArray()); } TimeSinceLastTaunt = 0; PlaySound(path); }