public override void Tick(float dt, ref Input_t input) { var move = _critter.lastKnownPosition - _critter.position; move.y = 0; input.movement = move; input.look = move.normalized; }
public override void Simulate(float dt, Input_t input) { base.Simulate(dt, input); if (!alive) { decayTime -= Time.deltaTime; if (decayTime <= 0) { Destroy(); } return; } if (canAttack) { for (int i = 0; i < AttackState.MaxAttackTypes; i++) { var attackState = input.attacks[i]; if (attackState != null) { Weapon w = GetInventorySlot(attackState.weaponIndex) as Weapon; if (w != null) { if (input.IsPressed(attackState.inputState)) { w.Charge(dt, 1); } else { w.chargeTime = 0; } if (input.JustReleased(attackState.inputState)) { w.Attack(this, attackState.attackIndex); } } } } } else { foreach (var weapon in getInventory()) { Weapon w = weapon as Weapon; if (w != null) { w.chargeTime = 0; } } } }
public override void Tick(float dt, ref Input_t input) { if (!_critter.hasLastKnownPosition) { input.movement = Vector3.zero; input.inputs[(int)InputType.Jump] = InputState.Released; input.inputs[(int)InputType.AttackRight] = InputState.Released; } else { var diff = _critter.rigidBody.position - _critter.lastKnownPosition; var desiredPos = _critter.lastKnownPosition + diff.normalized * data.fleeRange; var move = desiredPos - _critter.position; move.y = 0; float dist = diff.magnitude; input.movement = move.normalized; input.look = -diff; } }
private Input_t GetInputFromAI(float dt) { Input_t input = new Input_t(); input.look = new Vector3(Mathf.Sin(yaw), 0, Mathf.Cos(yaw)); if (team == gameMode.teams[0]) { return(input); } UpdateAggro(dt); if (curBehavior != null && !curBehavior.IsValid()) { behaviorUpdateTimer = 0; curBehavior = null; } behaviorUpdateTimer -= dt; if (behaviorUpdateTimer <= 0) { behaviorUpdateTimer += data.behaviorUpdateTime; // Evaluate behaviors List <CritterBehavior.EvaluationScore> possibleBehaviors = new List <CritterBehavior.EvaluationScore>(); float totalScore = 0; foreach (var b in behaviors) { var score = b.Evaluate(); if (score.score > 0) { if (b.scoreMultiplier > 0) { score.score *= b.scoreMultiplier; } possibleBehaviors.Add(score); totalScore += score.score; } } // Choose a behavior if (possibleBehaviors.Count > 0) { float chooseScore = GameManager.instance.randomNumber * totalScore; foreach (var b in possibleBehaviors) { chooseScore -= b.score; if (chooseScore <= 0) { if (curBehavior != b.behavior) { b.behavior.Start(); curBehavior = b.behavior; } break; } } } } // Execute the behavior if (curBehavior != null) { curBehavior.Tick(dt, ref input); } return(input); }
override public void Simulate(float dt, Input_t input) { if (!alive) { return; } if (tradePartner != null) { var diff = tradePartner.position - position; if (diff.magnitude > data.tradePartnerCancelDistance) { SetTradePartner(null); } } if (input.JustPressed(InputType.Swap)) { if (tradePartner != null) { SetTradePartner(null); } else if (mount != null) { SetMount(null); } else { SwapWeapons(); } } if (input.JustPressed(InputType.Interact)) { Interact(); } bool isCasting = false; Weapon itemLeft, itemRight; GetEquippedWeapons(out itemLeft, out itemRight); if (canAttack) { if (itemLeft != null) { if (itemLeft.CanCast()) { if (input.JustReleased(InputType.AttackLeft)) { if (itemLeft.chargeTime < itemLeft.data.jabChargeTime) { itemLeft.Attack(this, 0); isCasting = true; } } } } if (itemRight != null) { if (itemRight.CanCast()) { if (input.JustReleased(InputType.AttackRight)) { itemRight.Attack(this, 0); isCasting = true; } } } if (itemLeft != null) { if (itemLeft.CanCast() && input.IsPressed(InputType.AttackLeft)) { itemLeft.Charge(dt, 0); isCasting = true; } else { if (itemLeft.attackHand == 0) { itemLeft.chargeTime = 0; } } } if (itemRight != null) { if (itemRight.CanCast() && input.IsPressed(InputType.AttackRight)) { itemRight.Charge(dt, 1); isCasting = true; } else { if (itemRight.attackHand == 1) { itemRight.chargeTime = 0; } } } } attackTargetPreview = GetAttackTarget(yaw, 20, 360 * Mathf.Deg2Rad, null); if (isCasting) { SetTradePartner(null); } base.Simulate(dt, input); UpdateStats(dt); }
public override Input_t GetInput(float dt) { Input_t input = base.GetInput(dt); Vector3 forward = Vector3.forward; if (Client.Actors.ClientPlayerController.localPlayer != null) { float cameraYaw = Client.Actors.ClientPlayerController.localPlayer.cameraController.GetYaw(); forward = new Vector3(Mathf.Sin(cameraYaw), 0, Mathf.Cos(cameraYaw)); } for (int i = 0; i < (int)InputType.Count; i++) { if ((cur.buttons & (0x1 << i)) != 0) { if ((last.buttons & (0x1 << i)) == 0) { input.inputs[i] = InputState.JustPressed; } else { input.inputs[i] = InputState.Pressed; } } else { if ((last.buttons & (0x1 << i)) != 0) { input.inputs[i] = InputState.JustReleased; } else { input.inputs[i] = InputState.Released; } } } var right = Vector3.Cross(Vector3.up, forward); input.movement += forward * (float)cur.fwd / 127f; input.movement += right * (float)cur.right / 127f; if (input.movement.magnitude > 1) { input.movement.Normalize(); } Vector3 moveDir; if (input.movement != Vector3.zero) { moveDir = input.movement.normalized; } else { moveDir = new Vector3(Mathf.Sin(yaw), 0, Mathf.Cos(yaw)); } if (canStrafe) { if (cur.lookFwd != 0 || cur.lookRight != 0) { input.look += forward * (float)cur.lookFwd / 127f; input.look += right * (float)cur.lookRight / 127f; } else { input.look = new Vector3(Mathf.Sin(yaw), 0, Mathf.Cos(yaw)); //if (input.movement != Vector3.zero && Input.GetJoystickNames().Length > 0) { // input.look = input.movement.normalized; //} } } else { if (mount != null) { input.look = moveDir; } else if (tradePartner != null) { var lookDir = (tradePartner.position - position); lookDir.y = 0; input.look = lookDir.normalized; } if (input.movement != Vector3.zero) { input.look = moveDir; } } return(input); }