private void Start() { //apply humanoid force :o motorMovementForceObject.InitializeNonSerializedFields(CanExertMotorForce, affectedForceObject, this); humanoidForce = new CustomForce(affectedForceObject, motorMovementForceObject, true, float.NegativeInfinity); humanoidCollider = affectedForceObject.GetComponent <Collider>(); foreach (var key in acceptedInstantaniousGroundedForceInputs.Keys) { if (acceptedInstantaniousGroundedForceInputs[key].applyCooldown > 0) { cooldownAdjustableGroundedForceKeys.Add(key); } } foreach (var key in acceptedInstantaniousLevitatingForceInputs.Keys) { if (acceptedInstantaniousLevitatingForceInputs[key].applyCooldown > 0) { cooldownAdjustableLevitatingForceKeys.Add(key); } } //game properties animChecksSeconds = GameProperties.Singleton.AnimationCheckBuffer; StartCoroutine(AnimationCheckEnumeration(animChecksSeconds)); }
public void ApplyNewForce(CustomForce f) { if (f.AppliedFor == float.NegativeInfinity) { if (f.IsLastForce) { appliedConstantForcesLast.Add(f); } else { appliedConstantForces.Add(f); } } else { if (f.IsLastForce) { appliedForcesLast.Add(f); } else { appliedForces.Add(f); } } f.SetParentForceObject(this); onNewForceAdded?.Invoke(this, f); }
public void RemoveForce(CustomForce f) { if (f.AppliedFor == float.NegativeInfinity) { if (appliedConstantForces.Remove(f) || appliedConstantForcesLast.Remove(f)) { f.RemoveParentForceObject(this); } else { Debug.LogError("ForceObject.RemoveForce() was called with a reference to a force that it does not own."); } } else { if (appliedForces.Remove(f) || appliedForcesLast.Remove(f)) { f.RemoveParentForceObject(this); } else { Debug.LogError("ForceObject.RemoveForce() was called with a reference to a force that it does not own."); } } onForceRemoved?.Invoke(this, f); }
//TODO will caching getter values change performance? public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { Vector3 projection = Vector3.Project(objectAppliedTo.GetRecentNetAcceleration(), NormalVector); if (projection.magnitude < (projection - NormalVector).magnitude) { return(Vector3.zero); } return(-projection * NormalForceMultiplier); }
private void Start() { if (parentObject != null) { return; } Force = _force; parentForce = new CustomForce(editorSetApply.appliedTo, this, editorSetApply.isPure, editorSetApply.infiniteTimeForce ? float.NegativeInfinity : editorSetApply.applyTime); parentObject = editorSetApply.appliedTo; }
public void AddCustomForce(CustomForce force) { ForceRunner runner = new ForceRunner(force); _forceRunners.Add(runner); if (debugMode) { Debug.Log("Added custom force " + force.ToString()); } }
public bool CeaseForceApplication() { if (currentParent == null) { return(false); } currentParent.RemoveForce(currentForceInstance); currentParent = null; currentForceInstance = null; return(true); }
/// <summary> /// Called from parent's Update() /// Calculates player movement and adds any dash forces /// </summary> protected override void HandleAdditionalMovement() { Vector2 moveDirection = CalculateMovementDirection(); Vector2 dashDirection = CalculateDashDirection(); if (moveDirection != Vector2.zero) { totalMovement += moveSpeed * moveDirection * Time.deltaTime; } if (dashDirection != Vector2.zero) { CustomForce force = new CustomForce(_dashDropoffModel, dashDirection); this.AddCustomForce(force); } }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { if (!canExertMotorForceCheck()) { //NOT GROUNDED //do pure speed efforts //Vector3 currentSpeed return(Vector3.zero); } //GROUNDED if (pureSpeedDirty) { UndirtyPureSpeed(); } Vector3 forwardForce = motorMovementTransform.forward * forwardAccelerations[currentForwardIndex]; Vector3 rightForce = motorMovementTransform.right * backwardAccelerations[currentRightIndex]; Vector3 leftForce = -motorMovementTransform.right * rightAccelerations[currentLeftIndex]; Vector3 backwardForce = -motorMovementTransform.forward * leftAccelerations[currentBackwardIndex]; Vector3 adjustedWalkPlaneSpeed = Vector3.ProjectOnPlane(objectAppliedTo.GetRecentNetSpeed(), groundDir); Vector3 resultantForce = forwardForce + rightForce + leftForce + backwardForce; if (adjustedWalkPlaneSpeed.magnitude < NoMovementCutoff && resultantForce.magnitude < NoMovementCutoff) { objectAppliedTo.DirectAdjustAddSpeed(-adjustedWalkPlaneSpeed); return(Vector3.zero); } if (adjustedWalkPlaneSpeed.magnitude > maximumSpeedsPerIndex[currentMaxIndex]) { resultantForce += -adjustedWalkPlaneSpeed.normalized * adjustmentAccelerations[currentMaxIndex]; } //TODO doing it with just if might be faster becasue there is no addition with vector3.zero. Do diagnostic if releasing this code separately. return(resultantForce); }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { if (currentTime > switchingForces[currentIndex].time) { if (!repeatForever) { repetitionTimes--; if (repetitionTimes < 1) { objectAppliedTo.QueueRemoveForce(parentForce); } } currentTime = 0; currentIndex = (currentIndex + 1) % switchingForces.Length; } currentTime += Time.fixedDeltaTime; Vector3 force = switchingForces[currentIndex].forceVector; return(switchingForces[currentIndex].isLocal? (Vector3)(currentAppliedObject.transform.localToWorldMatrix * force) : force); }
//TODO will caching getter values change performance? public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { return((-objectAppliedTo.GetRecentNetSpeed().normalized * Mathf.Lerp(0, objectAppliedTo.GetObjectDragValue(), objectAppliedTo.GetRecentNetSpeed().magnitude / objectAppliedTo.GetAdjustedTrueMaximumSpeed())) * dragForceCoefficient); }
/// <summary> /// remove force after current physics call is complete. /// </summary> public void QueueRemoveForce(CustomForce f) { queuedRemovals.Add(f); }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { return((Vector3.Project(constantForce, objectAppliedTo.GetRecentNetSpeed()).magnitude > upToSpeed)? Vector3.zero : constantForce); }
/// <summary> /// /// </summary> /// <param name="appliedTo"></param> /// <param name="isPure"></param> /// <param name="appliedFor"> set to negative infinity to make constant force.</param> public void ApplyForce(ForceObject appliedTo, bool isPure, float appliedFor) { parentForce = new CustomForce(appliedTo, this, isPure, appliedFor); parentObject = appliedTo; }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { return(objectAppliedTo.transform.localToWorldMatrix * Force); }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { Vector3 dist = towardsTransform.transform.position - objectAppliedTo.transform.position; return((dist).normalized * (magnitude + distanceExtraCoeff * dist.magnitude)); }
public ForceRunner(CustomForce f) { _force = f; _expiryTime = _force.Lifetime; }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { return(Vector3.up * 12); }
public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo) { Vector3 between = objectAppliedTo.transform.position - distantTransform.transform.position; return((between.magnitude > minDistance) ? Vector3.zero : between.normalized *magnitude); }
/// <summary> /// /// </summary> /// <param name="parentObject"></param> /// <param name="isPure"></param> /// <param name="applyFor"> set to negative infinity for application until not. </param> /// <returns></returns> public void ApplyForce(ForceObject parentObject, bool isPure, float applyFor) { currentParent = parentObject; currentForceInstance = new CustomForce(parentObject, this, isPure, applyFor, true); }