public void Execute(Entity entity, int index, DynamicBuffer <VelocityCurveBuffer> velocityCurveBuffer, ref VelocityCurve velocityCurve, ref SideScrollingCharacterController sideScrollingCharacterController, [ReadOnly] ref SolidAgent solidAgent) { //Z axis is always 0 velocityCurve.Z = VelocityCurveAxis.Zero(); //Vertical Movement ComputeVerticalMovement(ref velocityCurve, ref sideScrollingCharacterController, ref solidAgent); //Horizontal Movement ComputeHorizontalMovement(ref velocityCurve, ref sideScrollingCharacterController, ref solidAgent); //Add this velocity curve to the character's velocity curve buffer velocityCurveBuffer.Add(new VelocityCurveBuffer { VelocityCurveEntity = entity }); }
public void Execute(Entity entity, int index, DynamicBuffer <VelocityCurveBuffer> velocityCurveBuffer, ref VelocityCurve velocityCurve, ref MovingPlatformController movingPlatformController, ref Translation translation) { //The platform never moves on the Z axis velocityCurve.Z = VelocityCurveAxis.Zero(); //Check if we've reached our current destination float3 destination = movingPlatformController.IsMovingTowardsA ? movingPlatformController.PositionA : movingPlatformController.PositionB; float distanceToDestination = math.abs(math.distance(translation.Value, destination)); if (distanceToDestination == 0.0f) { //Reverse the destination movingPlatformController.IsMovingTowardsA = !movingPlatformController.IsMovingTowardsA; destination = movingPlatformController.IsMovingTowardsA ? movingPlatformController.PositionA : movingPlatformController.PositionB; distanceToDestination = math.abs(math.distance(translation.Value, destination)); } //Move towards the destination, being carefull not to move past it float distanceToMoveThisTimeStep = DeltaTime * movingPlatformController.AbsoluteVelocity; float distanceToMoveThisTimeStepSquared = distanceToMoveThisTimeStep * distanceToMoveThisTimeStep; float3 distanceAvailableToMove = destination - translation.Value; float distanceAvailableToMoveSquared = math.lengthsq(distanceAvailableToMove); float3 directionToMove = math.normalize(distanceAvailableToMove); float3 linearVelocity = new float3(); if (distanceAvailableToMoveSquared < distanceToMoveThisTimeStepSquared) { linearVelocity = distanceAvailableToMove / DeltaTime; } else { linearVelocity = directionToMove * movingPlatformController.AbsoluteVelocity; } //Set the velocity curve velocityCurve.X = VelocityCurveAxis.Linear(linearVelocity.x > 0.0f, math.abs(linearVelocity.x)); velocityCurve.Y = VelocityCurveAxis.Linear(linearVelocity.y > 0.0f, math.abs(linearVelocity.y)); //Add this velocity curve to the moving platform's velocity curve buffer velocityCurveBuffer.Add(new VelocityCurveBuffer { VelocityCurveEntity = entity }); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var componentData = new JeffreyDufseth.VelocityCurveManagement.VelocityCurve { X = VelocityCurveAxis.Zero(), Y = VelocityCurveAxis.Zero(), Z = VelocityCurveAxis.Zero() }; dstManager.AddComponentData(entity, componentData); }
public void Execute(ref VelocityCurve velocityCurve, ref WindController windController) { //The wind never blows on the Z axis velocityCurve.Z = VelocityCurveAxis.Zero(); //Turn the wind on and off windController.ElapsedTime += DeltaTime; if (windController.IsBlowing && (windController.ElapsedTime > windController.OnTime)) { //Turn the wind off. windController.IsBlowing = false; windController.ElapsedTime = 0.0f; velocityCurve.X = VelocityCurveAxis.Quadratic(velocityCurve.X.CurrentVelocity, windController.WindDirection.x < 0.0f, windController.WindAbsoluteDeceleration * math.abs(windController.WindDirection.x), 0.0f); velocityCurve.Y = VelocityCurveAxis.Quadratic(velocityCurve.Y.CurrentVelocity, windController.WindDirection.y < 0.0f, windController.WindAbsoluteDeceleration * math.abs(windController.WindDirection.y), 0.0f); } else if (!windController.IsBlowing && (windController.ElapsedTime > windController.OffTime)) { //Turn the wind on. windController.IsBlowing = true; windController.ElapsedTime = 0.0f; velocityCurve.X = VelocityCurveAxis.Quadratic(velocityCurve.X.CurrentVelocity, windController.WindDirection.x > 0.0f, windController.WindAbsoluteDeceleration * math.abs(windController.WindDirection.x), windController.WindAbsoluteMaximumVelocity * math.abs(windController.WindDirection.x)); velocityCurve.Y = VelocityCurveAxis.Quadratic(velocityCurve.Y.CurrentVelocity, windController.WindDirection.y > 0.0f, windController.WindAbsoluteDeceleration * math.abs(windController.WindDirection.y), windController.WindAbsoluteMaximumVelocity * math.abs(windController.WindDirection.y)); } }