protected override void GetFromAttached() { transform.position = ReferenceTransform.ToRelPos(AttachedRigidbody.GetPosition()); transform.rotation = ReferenceTransform.ToRelRot(AttachedRigidbody.GetRotation()); Velocity = ReferenceRigidbody.ToRelVel(AttachedRigidbody.GetVelocity(), AttachedRigidbody.GetPosition()); AngularVelocity = ReferenceRigidbody.ToRelAngVel(AttachedRigidbody.GetAngularVelocity()); }
private IEnumerator PropulsionCoroutine() { float propulsionTimer = 0f; if (cancelVelocity) { AttachedRigidbody.velocity = Vector2.zero; AttachedRigidbody.angularVelocity = 0f; } while (running) { AttachedRigidbody.AddForce(PropulsionDirection * populsionForce); yield return(new WaitForFixedUpdate()); if (propulsionDuration > 0f) { propulsionTimer += Time.fixedDeltaTime; if (propulsionTimer > propulsionDuration) { running.Value = false; } } else if (propulsionDuration == 0f) { running.Value = false; } } propulsionCoroutine = null; if (oneShot) { enabled = false; } }
protected override void ApplyToAttached() { ApplyToSector(); if (!ReferenceTransform) { return; } var targetPos = ReferenceTransform.FromRelPos(transform.position); var targetRot = ReferenceTransform.FromRelRot(transform.rotation); var positionToSet = targetPos; var rotationToSet = targetRot; if (UseInterpolation) { positionToSet = ReferenceTransform.FromRelPos(SmoothPosition); rotationToSet = ReferenceTransform.FromRelRot(SmoothRotation); } AttachedRigidbody.MoveToPosition(positionToSet); AttachedRigidbody.MoveToRotation(rotationToSet); var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos); var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity); AttachedRigidbody.SetVelocity(targetVelocity); AttachedRigidbody.SetAngularVelocity(targetAngularVelocity); }
/// Dont do base... this is a replacement! protected override void ApplyToAttached() { ApplyToSector(); if (!ReferenceTransform) { return; } var targetPos = ReferenceTransform.FromRelPos(transform.position); _updateCount++; if (_updateCount >= ForcePositionAfterUpdates) { _updateCount = 0; var targetRot = ReferenceTransform.FromRelRot(transform.rotation); AttachedRigidbody.SetPosition(targetPos); AttachedRigidbody.SetRotation(targetRot); } var targetVelocity = ReferenceRigidbody.FromRelVel(Velocity, targetPos); var targetAngularVelocity = ReferenceRigidbody.FromRelAngVel(AngularVelocity); SetVelocity(AttachedRigidbody, targetVelocity); AttachedRigidbody.SetAngularVelocity(targetAngularVelocity); }
private void FixedUpdate() { if (IsInFluid && currentFluid != null) { surfacePoint = AttachedRigidbody.Distance(currentFluid).pointB; AttachedRigidbody.AddForce(FloatForce()); } }
private void FixedUpdate() { Vector2 localDown = transform.rotation * Vector2.down; AttachedRigidbody.AddForce(localDown * gravityForce); fallSpeed.Value = Mathf.Max(Vector2.Dot(AttachedRigidbody.velocity, localDown), 0f); isFalling.Value = (fallSpeed > fallVelocityThreshold); }
protected void SetEulerAngles(Vector3 eulerAngles) { if (null == AttachedRigidbody) { Debug.LogError(name + " did not find RigidBody next to it, or parented to it."); } else { AttachedRigidbody.angularVelocity = Vector3.zero; if (AttachedRigidbody.isKinematic) { AttachedRigidbody.transform.eulerAngles = eulerAngles; } else { AttachedRigidbody.MoveRotation(Quaternion.Euler(eulerAngles)); } } }
protected void SetRotation(Quaternion rotation) { if (null == AttachedRigidbody) { Debug.LogError(name + " did not find RigidBody next to it, or parented to it."); } else { AttachedRigidbody.angularVelocity = Vector3.zero; if (AttachedRigidbody.isKinematic) { AttachedRigidbody.transform.rotation = rotation; } else { AttachedRigidbody.MoveRotation(rotation); } } }
protected void SetPosition(Vector3 position) { if (null == AttachedRigidbody) { Debug.LogError(name + " did not find RigidBody next to it, or parented to it."); } else { AttachedRigidbody.velocity = Vector3.zero; if (AttachedRigidbody.isKinematic) { AttachedRigidbody.transform.position = position; } else { AttachedRigidbody.MovePosition(position); } } }