public static MovementForce AddMovementForce(Movable target, Vector3 force, float duration = 0, bool impactsAnimation = false, bool autoStart = true, bool destroyOnEnd = true, MoveCompiler.Movable_OnMoveFactorEndCallback callback = null) { if (callback == null) { callback = delegate() { }; } MovementForce movementForce = target.gameObject.AddComponent <MovementForce>(); movementForce.force = force; movementForce.impactsAnimation = impactsAnimation; if (duration > 0) { movementForce.hasDuration = true; movementForce.duration = duration; } movementForce.callback = delegate() { callback(); if (destroyOnEnd) { Destroy(movementForce); } }; if (autoStart) { movementForce.StartMovementForce(); } return(movementForce); }
protected void RepelTarget() { Movable movableTarget = target.GetComponent <Movable>(); Vector3 repelForce = Helper.MultiplyVector3By((target.transform.position - ennemyController.transform.position).normalized, repelDistance * 10); float repelDuration = 0.1f; if (movableTarget != null) { movableTarget.RestrainMovements(); MovementForce.AddMovementForce(movableTarget, repelForce, repelDuration, false, true, true, delegate() { movableTarget.UnrestrainMovements(); }); } else { // not supported, so not bumped Debug.Log("Unsupported bumpable target of localIdInFile " + Helper.GetObjectLocalIdInFile(this) + ". Make sure it has the Movable Component."); } }
public static void WriteMovementForceWithDirection(MovementForce movementForce, WorldPacket data, Position objectPosition = null) { data.WritePackedGuid(movementForce.ID); data.WriteVector3(movementForce.Origin); if (movementForce.Type == 1 && objectPosition != null) // gravity { Vector3 direction = Vector3.Zero; if (movementForce.Magnitude != 0.0f) { Position tmp = new Position(movementForce.Origin.X - objectPosition.GetPositionX(), movementForce.Origin.Y - objectPosition.GetPositionY(), movementForce.Origin.Z - objectPosition.GetPositionZ()); float lengthSquared = tmp.GetExactDistSq(0.0f, 0.0f, 0.0f); if (lengthSquared > 0.0f) { float mult = 1.0f / (float)Math.Sqrt(lengthSquared) * movementForce.Magnitude; tmp.posX *= mult; tmp.posY *= mult; tmp.posZ *= mult; float minLengthSquared = (tmp.GetPositionX() * tmp.GetPositionX() * 0.04f) + (tmp.GetPositionY() * tmp.GetPositionY() * 0.04f) + (tmp.GetPositionZ() * tmp.GetPositionZ() * 0.04f); if (lengthSquared > minLengthSquared) { direction = new Vector3(tmp.posX, tmp.posY, tmp.posZ); } } } data.WriteVector3(direction); } else { data.WriteVector3(movementForce.Direction); } data.WriteUInt32(movementForce.TransportID); data.WriteFloat(movementForce.Magnitude); data.WriteBits(movementForce.Type, 2); data.FlushBits(); }