private void fortuneTellerUpdate() { if (player == PlayerControl.LocalPlayer && !meetingFlag) { foreach (PlayerControl p in PlayerControl.AllPlayerControls) { if (!progress.ContainsKey(p.PlayerId)) { progress[p.PlayerId] = 0f; } if (p.isDead()) { continue; } var fortuneTeller = PlayerControl.LocalPlayer; float distance = Vector3.Distance(p.transform.position, fortuneTeller.transform.position); // 障害物判定 bool anythingBetween = PhysicsHelpers.AnythingBetween(p.GetTruePosition(), fortuneTeller.GetTruePosition(), Constants.ShipAndObjectsMask, false); if (!anythingBetween && distance <= FortuneTeller.distance && progress[p.PlayerId] < duration) { progress[p.PlayerId] += Time.fixedDeltaTime; } } } }
static PlayerControl FindClosestTarget(ref PlayerControl local) { PlayerControl result = null; if (!ShipStatus.Instance) { return(null); } float distance = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; var truePos = local.GetTruePosition(); foreach (var p in GameData.Instance.AllPlayers) { if (!p.Disconnected && p.PlayerId != local.PlayerId && !p.IsDead && p.Object.CanMove) { var control = p.Object; if (control != null) { var vector = control.GetTruePosition() - truePos; float magnitude = vector.magnitude; if (magnitude <= distance && !PhysicsHelpers.AnyNonTriggersBetween(truePos, vector.normalized, magnitude, Constants.InfinitySymbol)) { result = control; distance = magnitude; } } } } return(result); }
public static PlayerControl FindClosestPlayer(this PlayerControl player) { PlayerControl result = null; float num = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!ShipStatus.Instance) { return(null); } Vector2 truePosition = player.GetTruePosition(); List <GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers.ToArray().ToList(); for (int i = 0; i < allPlayers.Count; i++) { GameData.PlayerInfo playerInfo = allPlayers[i]; if (!playerInfo.Disconnected && playerInfo.PlayerId != player.PlayerId && !playerInfo.IsDead) { PlayerControl @object = playerInfo.Object; if (@object) { Vector2 vector = @object.GetTruePosition() - truePosition; float magnitude = vector.magnitude; if (magnitude <= num && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector.normalized, magnitude, Constants.ShipAndObjectsMask)) { result = @object; num = magnitude; } } } } return(result); }
public static bool Vent_CanUse(Vent __instance, [HarmonyArgument(1)] ref bool canUse, [HarmonyArgument(2)] ref bool couldUse, ref float __result) { BaseRole?role = PlayerControl.LocalPlayer.GetRole(); if (role == null) { return(true); } couldUse = canUse = role.CanVent(__instance); __result = float.MaxValue; if (canUse) { Vector2 myPos = PlayerControl.LocalPlayer.GetTruePosition(); Vector3 ventPos = __instance.transform.position; __result = Vector2.Distance(myPos, ventPos); canUse &= __result <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(myPos, ventPos, Constants.ShipOnlyMask, false); } return(false); }
public static bool Prefix(Vent __instance, PlayerControl NMEAPOJFNKA) { PlayerControl pc = NMEAPOJFNKA; if (!__instance.ExitVentAnim) { return(false); } var truePosition = PlayerControl.LocalPlayer.GetTruePosition(); Vector2 vector = pc.GetTruePosition() - truePosition; var magnitude = vector.magnitude; if (pc.AmOwner || magnitude < PlayerControl.LocalPlayer.myLight.LightRadius && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector.normalized, magnitude, ShipAndObjectsMask)) { __instance.GetComponent <SpriteAnim>().Play(__instance.ExitVentAnim, 1f); } if (pc.AmOwner && Constants.Method_3()) //ShouldPlaySfx { SoundManager.Instance.StopSound(ShipStatus.Instance.VentEnterSound); SoundManager.Instance.PlaySound(ShipStatus.Instance.VentEnterSound, false, 1f).pitch = UnityEngine.Random.Range(0.8f, 1.2f); } return(false); }
public static PlayerControl FindClosestTarget(PlayerControl currentPlayer) { PlayerControl playerControl1 = (PlayerControl)null; float num = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!(bool)ShipStatus.Instance) { return(null); } Vector2 truePosition = currentPlayer.GetTruePosition(); Il2CppSystem.Collections.Generic.List <GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers; for (int index = 0; index < allPlayers.Count; ++index) { GameData.PlayerInfo playerInfo = allPlayers[index]; if (!playerInfo.Disconnected && playerInfo.PlayerId != currentPlayer.PlayerId && !playerInfo.IsDead) { PlayerControl playerControl2 = playerInfo.Object; if ((bool)playerControl2) { Vector2 vector2 = playerControl2.GetTruePosition() - truePosition; float magnitude = vector2.magnitude; if (magnitude <= (double)num && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector2.normalized, magnitude, Constants.ShipAndObjectsMask)) { playerControl1 = playerControl2; num = magnitude; } } } } return(playerControl1); }
static bool Prefix(Console __instance, GameData.PlayerInfo __0, out bool __1, out bool __2) { float num = float.MaxValue; PlayerControl @object = __0.Object; var flag = @object.Is(RoleEnum.Glitch) || @object.Is(RoleEnum.Jester) || @object.Is(RoleEnum.Shifter) || @object.Is(RoleEnum.Executioner) || @object.Is(RoleEnum.Arsonist); Vector2 truePosition = @object.GetTruePosition(); Vector3 position = __instance.transform.position; __2 = ((!__0.IsDead || (PlayerControl.GameOptions.GhostsDoTasks && !__instance.GhostsIgnored)) && @object.CanMove && (__instance.AllowImpostor || (!flag && !__0.IsImpostor)) && (!__instance.onlySameRoom || MethodRewrites.InRoom(__instance, truePosition)) && (!__instance.onlyFromBelow || truePosition.y < position.y) && MethodRewrites.FindTask(__instance, @object)); __1 = __2; if (__1) { num = Vector2.Distance(truePosition, __instance.transform.position); __1 &= (num <= __instance.UsableDistance); if (__instance.checkWalls) { __1 &= !PhysicsHelpers.AnythingBetween(truePosition, position, Constants.ShadowMask, false); } } return(false); }
protected override void HandleShotRelease() { if (_isReloading) { return; } _isReloading = true; weaponStatusImage.enabled = true; weaponStatusImage.fillAmount = 0f; weaponStatusImage.color = Color.white; var proj = PoolManager.Instance.ReuseObject(_projectile, transform.position, transform.rotation); var projectileCollision = proj.GetComponentInChildren <ProjectileCollisionBehaviour> (); projectileCollision.aoeRadius = settings.aoeRadius; projectileCollision.damage = settings.damage; projectileCollision.crashSound = settings.explodeSound; PlayerAudioBehaviour.PlaySound(settings.launchSound, transform.position); var target = _crossHair.transform.position; float shotHeight = target.magnitude * settings.multiplier; proj.GetComponent <Rigidbody> ().velocity = PhysicsHelpers.velocityForBasketBallThrow(transform.position, target, shotHeight); _timeChanneled = 0f; }
public static PlayerControl getClosestPlayer(PlayerControl refPlayer, List <PlayerControl> AllPlayers) { var num = double.MaxValue; var refPosition = refPlayer.GetTruePosition(); PlayerControl result = null; foreach (var player in AllPlayers) { if (player.Data.IsDead || player.PlayerId == refPlayer.PlayerId || !player.Collider.enabled) { continue; } var playerPosition = player.GetTruePosition(); var distBetweenPlayers = Vector2.Distance(refPosition, playerPosition); var isClosest = distBetweenPlayers < num; if (!isClosest) { continue; } var vector = playerPosition - refPosition; if (PhysicsHelpers.AnyNonTriggersBetween( refPosition, vector.normalized, vector.magnitude, Constants.ShipAndObjectsMask )) { continue; } num = distBetweenPlayers; result = player; } return(result); }
static PlayerControl setAnyRoleTarget() { PlayerControl result = null; float num = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!ShipStatus.Instance) { return(result); } Vector2 truePosition = PlayerControl.LocalPlayer.GetTruePosition(); Il2CppSystem.Collections.Generic.List <GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { GameData.PlayerInfo playerInfo = allPlayers[i]; if (!playerInfo.Disconnected && playerInfo.PlayerId != PlayerControl.LocalPlayer.PlayerId && !playerInfo.IsDead) { PlayerControl @object = playerInfo.Object; if (@object && [email protected]) { Vector2 vector = @object.GetTruePosition() - truePosition; float magnitude = vector.magnitude; if (magnitude <= num && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector.normalized, magnitude, Constants.ShipAndObjectsMask)) { result = @object; num = magnitude; } } } } return(result); }
private void CalculateOrientationFromSurroundings() { var rayResults = PhysicsHelpers.CastRays(vehicleBounds.center, showOrientationCasters, 15, 15, 10, groundMask, Space.World); var rayHits = rayResults.Where(rayResult => rayResult.raycastHit); var nextUp = Vector3.up; if (rayHits.Count() > 0) { nextUp = (rayHits.Select(rayInfo => rayInfo.hitData[0].normal).Aggregate((firstRay, secondRay) => firstRay + secondRay) / rayHits.Count()).normalized; } up = Vector3.Lerp(up, nextUp, Time.fixedDeltaTime * 5); forward = Vector3.ProjectOnPlane(transform.forward, up).normalized; right = Quaternion.AngleAxis(90, up) * forward; if (showCalculatedUp) { Debug.DrawRay(vehicleBounds.center, up * 5, Color.green); } if (showCalculatedForward) { Debug.DrawRay(vehicleBounds.center, forward * 5, Color.blue); } if (showCalculatedRight) { Debug.DrawRay(vehicleBounds.center, right * 5, Color.red); } }
private void FireIfNeeded() { if (_fireRate <= 0f) { _fireRate = settings.projectileSpeed; var proj = PoolManager.Instance.ReuseObject(_projectile, transform.position, transform.rotation); var projectileCollision = proj.GetComponentInChildren <ProjectileCollisionBehaviour> (); projectileCollision.aoeRadius = settings.aoeRadius; projectileCollision.damage = settings.damage; projectileCollision.crashSound = settings.explodeSound; PlayerAudioBehaviour.PlaySound(settings.launchSound, transform.position); var target = _crossHair.transform.position; target.x += UnityEngine.Random.Range(-0.5f, 0.5f); target.z += UnityEngine.Random.Range(-0.5f, 0.5f); float shotHeight = target.magnitude * settings.multiplier; proj.GetComponent <Rigidbody> ().velocity = PhysicsHelpers.velocityForBasketBallThrow(transform.position, target, shotHeight); } _timeChanneled += Time.deltaTime; weaponStatusImage.fillAmount = _timeChanneled / settings.channelTime; weaponStatusImage.color = Color.Lerp(Color.white, Color.red, _timeChanneled / settings.channelTime); if (weaponStatusImage.fillAmount >= 1f) { _state = EMachineGunState.reloading; _timeChanneled = 0f; } _fireRate -= Time.deltaTime; }
// Update is called once per frame void Update() { if (parent != null) { currentSpeed = PhysicsHelpers.RecalculateVOverTime(currentSpeed, transform.position, MassKg, parent.transform.position, parent.MassKg, GameController.TimeConstant); transform.position += currentSpeed; } }
public override void ResolvePendencies() { if (apostleStatusVariables.isOnAir) { if (lastFramePositionWhileFalling >= rigidbody2D.position.y && rigidbody2D.velocity.y < 0) { distanceWhileFalling += lastFramePositionWhileFalling - rigidbody2D.position.y; } if (apostleStatusVariables.canJump && (rigidbody2D.velocity.y < 0 || MathHelpers.Approximately(rigidbody2D.velocity.y, 0, float.Epsilon))) { if (distanceWhileFalling >= minimumFallingDistanceForDamage) { apostle.TakeDamage(minimumDamageForFalling * distanceWhileFalling / minimumFallingDistanceForDamage); } distanceWhileFalling = 0; apostleStatusVariables.isOnAir = false; apostleController.RevokeControl(0.1f, true, ControlTypeToRevoke.AllMovement, monoBehaviour); } lastFramePositionWhileFalling = rigidbody2D.position.y; } else { lastFramePositionWhileFalling = 0; } if (!MathHelpers.Approximately(rigidbody2D.velocity.y, 0, float.Epsilon) && MathHelpers.Approximately(apostleController.VerticalMovement, 0, float.Epsilon) && apostleStatusVariables.isClimbingLadder) { PhysicsHelpers.ResetVelocityY(rigidbody2D); } if (!apostleStatusVariables.isClimbingStairs) { // PhysicsHelpers.IgnoreLayerCollision(rigidbody2D.gameObject.layer, LayerMask.NameToLayer("Stairs Ground"), // true); apostleCollisionHandler.SetLayerForCollisions(new[] { "Ground", "Ground Ignore" }); var leftRayCollider = apostleCollisionHandler.CastLeftwardRay(LayerMask.GetMask("Stairs Ground")).collider; var rightRayCollider = apostleCollisionHandler.CastRightwardRay(LayerMask.GetMask("Stairs Ground")).collider; if (leftRayCollider != null && !Physics2D.GetIgnoreCollision(capsuleCollider2D, leftRayCollider)) { PhysicsHelpers.IgnoreCollision(capsuleCollider2D, leftRayCollider, true); } else if (rightRayCollider && !Physics2D.GetIgnoreCollision(capsuleCollider2D, rightRayCollider)) { PhysicsHelpers.IgnoreCollision(capsuleCollider2D, rightRayCollider, true); } } }
private void SetOnStairsColliders(StairsController stairsController) { playerStatusVariables.isClimbingStairs = true; PhysicsHelpers.IgnoreCollision(capsuleCollider2D, stairsController.adjacentCollider, true); stairsController.adjacentCollider.gameObject.layer = LayerMask.NameToLayer("Ground Ignore"); PhysicsHelpers.IgnoreLayerCollision(rigidbody2D.gameObject.layer, LayerMask.NameToLayer("Stairs Ground"), false); playerCollisionHandler.SetLayerForCollisions(new[] { "Ground", "Stairs Ground" }); }
public void Effect(Vector3 aimDirection, bool imediate) { PhysicsHelpers.AddImpulseForce(throwForce, aimDirection, rigidbody2D); if (imediate) { durationCurrentTime = Time.time + duration; PhysicsHelpers.IgnoreLayerCollision(LayerMask.NameToLayer("Item"), LayerMask.NameToLayer("Enemy"), true); } }
void FixedUpdate() { vehicleBounds = transform.GetTotalBounds(Space.World); CalculateOrientationFromSurroundings(); if (control) { if (Input.GetKey(KeyCode.W)) { gas = 1; } else if (Input.GetKey(KeyCode.S)) { gas = -1; } else { gas = 0; } if (Input.GetKey(KeyCode.D)) { steer = 1; } else if (Input.GetKey(KeyCode.A)) { steer = -1; } else { steer = 0; } } float currentForwardVelocity = Vector3.Dot(CarBody.velocity, forward); if (gas > float.Epsilon || gas < -float.Epsilon) { CarBody.AddForce(PhysicsHelpers.CalculateRequiredForceForSpeed(CarBody.mass, currentForwardVelocity, Mathf.Clamp(currentForwardVelocity + gas * acceleration, -maxSpeed, maxSpeed)) * forward, ForceMode.Force); } float handlingMultiplier = handlingCurve.Evaluate(Mathf.Abs(currentForwardVelocity) / maxSpeed); if (steer > float.Epsilon || steer < -float.Epsilon) { forward = Quaternion.AngleAxis(steer * maxTurnRate * handlingMultiplier * Mathf.Sign(currentForwardVelocity), up) * forward; } ApplyFloatation(); ApplyOrientator(); ApplyFriction(); }
public void CheckForClimbingStairs() { if (playerStatusVariables.canClimbStairs && !playerStatusVariables.isClimbingStairs) { var collider = GetStairsTrigger(); if (collider != null) { var stairsController = collider.GetComponent <StairsController>(); if ((CheckIfObjectIsRight(stairsController.stairsCollider.transform.position) ? playerController.HorizontalMove > 0 : playerController.HorizontalMove < 0) && (stairsController.stairsTriggerType == StairsTriggerType.TopTrigger ? playerController.VerticalMovement < 0 : playerController.VerticalMovement > 0)) { SetOnStairsColliders(stairsController); } } } else if (playerStatusVariables.isClimbingStairs && (playerCollisionHandler.CheckForLayerCollision(LayerMask.GetMask("Ground"), 0.1f) || playerStatusVariables.isOnAir) && playerStatusVariables.canClimbStairs) { var collider = GetStairsTrigger(); if (collider != null) { var stairsController = collider.GetComponent <StairsController>(); var stairsCollider = stairsController.stairsCollider.GetComponent <BoxCollider2D>(); //A normal é sempre perpendicular ao plano, porém é necessário manter a rotação entre 29 e -29 var normal = stairsCollider.transform.up; if (CheckIfObjectIsRight(stairsController.stairsCollider.transform.position) ? PhysicsHelpers.SlopeInclinationRight(normal) ? rigidbody2D.velocity.y < 0 : rigidbody2D.velocity.y >= 0 : PhysicsHelpers.SlopeInclinationRight(normal) ? rigidbody2D.velocity.y >= 0 : rigidbody2D.velocity.y < 0) { playerStatusVariables.isClimbingStairs = false; PhysicsHelpers.IgnoreCollision(capsuleCollider2D, stairsController.adjacentCollider, false); stairsController.adjacentCollider.gameObject.layer = LayerMask.NameToLayer("Ground"); } } } }
public override void HoldMovementHandler() { switch (HorizontalMovementState) { case HorizontalMovementState.Idle: if (!playerStatusVariables.isOnAir) { PreventSlide(forceApplied); } break; case HorizontalMovementState.Walking: forceApplied = Walk(playerController.HorizontalMove, 1 * VelocityMultiplier); break; case HorizontalMovementState.Jogging: player.SpendStamina(5f, false); forceApplied = Jog(playerController.HorizontalMove, 1.5f * VelocityMultiplier); break; case HorizontalMovementState.Running: player.SpendStamina(10f, false); forceApplied = Run(playerController.HorizontalMove, 2f * VelocityMultiplier); break; case HorizontalMovementState.CrouchIdle: if (!playerStatusVariables.isOnAir) { PreventSlide(forceApplied); } break; case HorizontalMovementState.CrouchWalking: forceApplied = CrouchWalk(playerController.HorizontalMove, 0.75f); break; default: Debug.Log("ERRO"); break; } if (CheckForPreventSlideOnSlopes()) { PhysicsHelpers.PreventSlideOnSlopes(playerCollisionHandler.SurfaceAngle, playerCollisionHandler.SurfaceNormal, (HorizontalMovementState == HorizontalMovementState.Idle || HorizontalMovementState == HorizontalMovementState.CrouchIdle), rigidbody2D); } }
public void Shoot() { var raycastHit2DList = new RaycastHit2D[1]; Physics2D.Raycast(initialPosition, initialDirection, contactFilter2DForBulletCheck, raycastHit2DList, maxBulletDistance); raycastHit2D = raycastHit2DList[0]; PhysicsHelpers.AddImpulseForce(force, this.rigidbody2D); lastBulletPosition = rigidbody2D.position; if (raycastHit2D.collider == null) { DestroyBullet(2f); } }
public bool IsSafeLocation(Vector3 pos) { var playerCenterOffset = 1.1f; // offset from position to player center in Y-axis var crouchHalfHeight = .75f; // half the capsule height of crouching character var playerRadius = .36f; var capsuleBottom = pos + (playerCenterOffset - crouchHalfHeight + playerRadius) * Vector3.up; var capsuleTop = pos + (playerCenterOffset + crouchHalfHeight - playerRadius) * Vector3.up; if (Physics.CheckCapsule(capsuleBottom, capsuleTop, playerRadius, LayerMaskManager.TerrainConstructionsMachines, QueryTriggerInteraction.Ignore)) { return(false); } return(!PhysicsHelpers.IsInRock(pos + Vector3.up * playerCenterOffset)); }
private IEnumerator EffectCoroutine(float areaOfEffectAngle, Vector3 position) { var contactFilter2D = new ContactFilter2D { useTriggers = true, useLayerMask = true, layerMask = LayerMask.GetMask("Enemy", "Player") }; var collider2Ds = new Collider2D[5]; while (Time.time < durationCurrentTime && hasExploded) { var areaOfEffect = Physics2D.OverlapBox(position, new Vector2(area, 1), areaOfEffectAngle, contactFilter2D, collider2Ds); if (areaOfEffect > 0) { for (var i = 0; i < collider2Ds.Length; i++) { if (collider2Ds[i] != null) { PhysicsHelpers.IgnoreCollision(triggerCollider2D, collider2Ds[i], true); var enemy = collider2Ds[i].GetComponent <Enemy>(); if (enemy != null) { enemy.TakeDamage(damage * Time.fixedDeltaTime); } else { var player = collider2Ds[i].GetComponent <PlayerStatusController>(); if (player != null) { player.TakeDamage(damage * Time.fixedDeltaTime); } } } } } yield return(new WaitForFixedUpdate()); } CoroutineManager.DeleteCoroutine("EffectCoroutine"); Destroy(this.gameObject); }
public static bool Prefix(Vent __instance, ref float __result, [HarmonyArgument(0)] GameData.PlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse) { float num = float.MaxValue; PlayerControl @object = pc.Object; bool roleCouldUse = false; if (Engineer.engineer != null && Engineer.engineer == @object) { roleCouldUse = true; } else if (Jackal.canUseVents && Jackal.jackal != null && Jackal.jackal == @object) { roleCouldUse = true; } else if (Sidekick.canUseVents && Sidekick.sidekick != null && Sidekick.sidekick == @object) { roleCouldUse = true; } else if (pc.IsImpostor) { if (Janitor.janitor != null && Janitor.janitor == PlayerControl.LocalPlayer) { roleCouldUse = false; } else if (Mafioso.mafioso != null && Mafioso.mafioso == PlayerControl.LocalPlayer && Godfather.godfather != null && !Godfather.godfather.Data.IsDead) { roleCouldUse = false; } else { roleCouldUse = true; } } couldUse = ((@object.inVent || roleCouldUse) && !pc.IsDead && (@object.CanMove || @object.inVent)); canUse = couldUse; if (canUse) { Vector2 truePosition = @object.GetTruePosition(); Vector3 position = __instance.transform.position; num = Vector2.Distance(truePosition, position); canUse &= (num <= __instance.UsableDistance && !PhysicsHelpers.AnythingBetween(truePosition, position, Constants.ShipOnlyMask, false)); } __result = num; return(false); }
private void ApplyFriction() { float currentHorVelocity = Vector3.Dot(CarBody.velocity, right); float velocityFrictionMultiplier = frictionCurve.Evaluate(currentHorVelocity / maxSpeed); float forceToStop = PhysicsHelpers.CalculateRequiredForceForSpeed(CarBody.mass, currentHorVelocity, 0); CarBody.AddForce(right * forceToStop * velocityFrictionMultiplier, ForceMode.Force); Vector3 correctionTorque = CarBody.CalculateRequiredTorqueForRotation(castedOrientation, Time.fixedDeltaTime, maxCorrectionTorque); float maxTorque = 20; float correctionTorqueAmount = Vector3.Dot(correctionTorque, up); float torqueFrictionMultiplier = frictionCurve.Evaluate(correctionTorqueAmount / maxTorque); CarBody.AddTorque(up * correctionTorqueAmount, ForceMode.Force); }
// Helpers static PlayerControl setTarget(bool onlyCrewmates = false, bool targetPlayersInVents = false, List <PlayerControl> untargetablePlayers = null, PlayerControl targetingPlayer = null) { PlayerControl result = null; float num = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!ShipStatus.Instance) { return(result); } if (targetingPlayer == null) { targetingPlayer = PlayerControl.LocalPlayer; } if (targetingPlayer.Data.IsDead) { return(result); } Vector2 truePosition = targetingPlayer.GetTruePosition(); Il2CppSystem.Collections.Generic.List <GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { GameData.PlayerInfo playerInfo = allPlayers[i]; if (!playerInfo.Disconnected && playerInfo.PlayerId != targetingPlayer.PlayerId && !playerInfo.IsDead && (!onlyCrewmates || !playerInfo.IsImpostor)) { PlayerControl @object = playerInfo.Object; if (untargetablePlayers != null && untargetablePlayers.Any(x => x == @object)) { // if that player is not targetable: skip check continue; } if (@object && ([email protected] || targetPlayersInVents)) { Vector2 vector = @object.GetTruePosition() - truePosition; float magnitude = vector.magnitude; if (magnitude <= num && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector.normalized, magnitude, Constants.ShipAndObjectsMask)) { result = @object; num = magnitude; } } } } return(result); }
public static bool IsPlayerInUseRange(PlayerControl fromPlayer, PlayerControl toPlayer, float range = 0F) { float maxDistance = range > 0F ? range : GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!ShipStatus.Instance) { return(false); } Vector2 fromPosition = fromPlayer.GetTruePosition(); Vector2 distanceVector = toPlayer.GetTruePosition() - fromPosition; float distance = distanceVector.magnitude; return(distance <= maxDistance && !PhysicsHelpers.AnyNonTriggersBetween(fromPosition, distanceVector.normalized, distance, Constants.ShipAndObjectsMask)); }
/// <summary> /// Handles Collision with this instance. /// </summary> /// <param name="collider">The colliding object.</param> private void OnCollisionEnter2D(Collision2D collider) { if (collider.gameObject.tag == "Ball") { var physicalObject = collider.gameObject.GetComponent <PhysicalObject>(); var contact = collider.contacts.First(); var side = PhysicsHelpers.SideOfCollision(contact.point, this.gameObject); if (side == PhysicsHelpers.Side.Top || side == PhysicsHelpers.Side.Bottom) { float halfPaddle = this.Width / 2.0f; float speedModifier = Globals.SpeedModifier; float outX = (((collider.transform.position.x - this.Left) / halfPaddle) - 1.0f); float outY = -physicalObject.PreviousVelocity.normalized.y; collider.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(outX, outY) * speedModifier; } } }
public void ClimbOntoObstacle(Vector2 position) { PhysicsHelpers.SwitchGravity(rigidbody2D, false, currentGravityScale); PhysicsHelpers.ResetVelocityX(rigidbody2D); PhysicsHelpers.ResetVelocityY(rigidbody2D); rigidbody2D.isKinematic = true; playerController.RevokeControl(true, ControlTypeToRevoke.AllMovement); var coroutine = CoroutineManager.FindCoroutine("ClimbOntoObstacleCoroutine"); if (coroutine == null) { CoroutineManager.AddCoroutine(ClimbOntoObstacleCoroutine(position, climbingObstacleSmoothness), "ClimbOntoObstacleCoroutine"); } }
public Vector2 Dodge() { //Adicionar a colisão com inimigos depois PhysicsHelpers.ResetVelocityX(rigidbody2D); PhysicsHelpers.ResetVelocityY(rigidbody2D); var forceApplied = PhysicsHelpers.AddImpulseForce(dodgeForce, playerCollisionHandler.SurfaceAngle, playerCollisionHandler.SurfaceNormal, rigidbody2D, playerStatusVariables.facingDirection); playerStatusVariables.isDodging = false; playerController.RevokeControl(0.6f, true, ControlTypeToRevoke.AllMovement, monoBehaviour); PhysicsHelpers.IgnoreLayerCollision(rigidbody2D.gameObject.layer, LayerMask.NameToLayer("Enemy"), true, 0.6f); return(forceApplied); }
static bool Prefix(PlayerControl __instance, ref PlayerControl __result) { PlayerControl result = null; PlayerControl pl = __instance; float num = GameOptionsData.KillDistances[Mathf.Clamp(PlayerControl.GameOptions.KillDistance, 0, 2)]; if (!ShipStatus.Instance) { AnonymousImpostor.log.LogMessage("PlayerControl.FindClosestTarget was called:Target is null."); return(true); } Vector2 truePosition = pl.GetTruePosition(); Il2CppSystem.Collections.Generic.List <GameData.PlayerInfo> allPlayers = GameData.Instance.AllPlayers; for (int i = 0; i < allPlayers.Count; i++) { GameData.PlayerInfo playerInfo = allPlayers[i]; if (!playerInfo.Disconnected && playerInfo.PlayerId != pl.PlayerId && !playerInfo.IsDead) { PlayerControl @object = playerInfo.Object; if (@object) { Vector2 vector = @object.GetTruePosition() - truePosition; float magnitude = vector.magnitude; if (magnitude <= num && !PhysicsHelpers.AnyNonTriggersBetween(truePosition, vector.normalized, magnitude, Constants.ShipAndObjectsMask)) { result = @object; num = magnitude; } } } } try { AnonymousImpostor.log.LogMessage("PlayerControl.FindClosestTarget was called:Target is " + result.PlayerId + "'s player."); } catch { AnonymousImpostor.log.LogMessage("PlayerControl.FindClosestTarget was called:Target is null."); } __result = result; return(false); }