Example #1
0
 public void Update(CollisionState2D s)
 {
     direction = s.direction;
     becameGroundedThisFrame = s.becameGroundedThisFrame;
     movingDownSlope         = s.movingDownSlope;
     slopeAngle = s.slopeAngle;
 }
Example #2
0
    public EnemyMotor(PhysicsEntity e, Transform t)
        : base(e, t)
    {
        targetDirection = new CoreDirection(Direction2D.RIGHT);

        FrameCounter.Instance.OnUpdate += HandleUpdate;
    }
Example #3
0
    public CoreDirection GetInputPressed(CoreDirection oldInput, CoreDirection newInput)
    {
        var result = new CoreDirection();
        var prime  = GetInputPressed(oldInput.Vector, newInput.Vector);

        result.Update(prime);

        return(result);
    }
Example #4
0
    // Public methods
    public void Launch(Vector2 additionalVelocity, CoreDirection d)
    {
        var v = d.Vector * data.baseVelocity;

        v  += additionalVelocity * data.lobVelocityCoefficient;
        v.y = Mathf.Max(data.baseVelocity.y, v.y);

        entity.SetVelocity(v);
    }
Example #5
0
    public Motor(U e, Transform t)
    {
        direction = new CoreDirection();
        data      = ScriptableObject.CreateInstance <T>();

        entity = e;
        root   = t;

        Debug.Assert(e != null, "entity is null");
        Debug.Assert(t != null, "root is null");
    }
Example #6
0
    public PlayerMotor(PlayerCharacterEntity pc,
                       Transform t)
        : base(pc, t)
    {
        input = new InputSnapshot <PlayerInput>();
        wallJumpImpactDirection = new CoreDirection();

        data = ScriptableObject.CreateInstance <PlayerMotorData>();

        direction = data.initialDirection;

        FrameCounter.Instance.OnUpdate += HandleUpdate;
    }
Example #7
0
    // todo: should return leftmost collider of four colliders
    public RaycastHit2D Check(CoreDirection direction, float distance)
    {
        ContactFilter2D filter  = new ContactFilter2D();
        var             results = new RaycastHit2D[1];

        // todo: this should be a param
        filter.layerMask = LayerMask.NameToLayer("Obstacle");

        body.Cast(direction.Vector, filter, results, distance);

        // Return the first index
        return(results[0]);
    }
Example #8
0
    private void HandleNotGrounded()
    {
        var movement         = input.held.direction.Vector;
        var resolvedVelocity = entity.velocity;

        // Air directional influence
        resolvedVelocity.x += movement.x * data.accelerationHorizontalAir;
        resolvedVelocity.x  = Mathf.Clamp(resolvedVelocity.x, -data.velocityHorizontalAirMax, data.velocityHorizontalAirMax);

        // Check for wall jump.
        if (jumpCount > 0 && input.pressed.jump)
        {
            // Buffer collision state X frames
            // Check if .left is in buffer up to Y frames back
            // Wall jump direction check prevents motor from indefinitely climbing up the same wall.
            // Motor jump off the opposite wall for this to reset.
            var bufferedCollision = entity.GetBufferedCollisionState();

            if (Mathf.Abs(wallJumpImpactDirection.Vector.x) < 1 ||
                CoreDirection.IsOppositeHorizontal(wallJumpImpactDirection, bufferedCollision.direction))
            {
                if (Mathf.Abs(bufferedCollision.direction.Vector.x) > 0)
                {
                    wallJumpImpactDirection.Update(bufferedCollision.direction);
                    wallJumpImpactDirection.ClearVertical();

                    var velocityX = -bufferedCollision.direction.Vector.x * data.velocityWallJumpHorizontal;

                    if (CoreDirection.IsSameHorizontal(bufferedCollision.direction, input.held.direction))
                    {
                        // Zero out x velocity if input is in same direction as the collision side. Meant to help climbing up.
                        velocityX = 0;
                    }

                    resolvedVelocity.x = velocityX;
                    resolvedVelocity.y = data.velocityWallJumpVertical;

                    CallbackManager manager = new CallbackManager();
                }
            }
        }

        // Cut short the jump if the motor bumped something above.
        if (entity.collision.current.state.Above)
        {
            additiveJumpFrameCount = data.frameLimitJumpAdditive;
        }

        entity.SetVelocity(resolvedVelocity);
    }
Example #9
0
    public void HandleUpdate(long count, float deltaTime)
    {
        var collision = entity.collision.current;

        if (collision.state.Below)
        {
            var v = data.baseVelocity;

            v.x *= targetDirection.Vector.x;

            entity.SetVelocity(v);
        }
        if (!collision.state.direction.IsEmptyHorizontal())
        {
            // Hit something on the left or right
            if (CoreDirection.IsSameHorizontal(targetDirection, collision.state.direction))
            {
                targetDirection.FlipHorizontal();
            }
        }

        ComputeDirection(entity.velocity);
    }
Example #10
0
    public void ApplyInput(InputSnapshot <HandGrenadeInput> input)
    {
        if (input.pressed.launch && !skeleton.IsActive(Limb.GRENADE, Logical.AND))
        {
            skeleton.grenade.entity.SetPosition(skeleton.hand.entity.Position);

            skeleton.SetActive(Limb.GRENADE, true);
            skeleton.SetActive(Limb.HAND, false);

            Physics2D.IgnoreCollision(skeleton.body.entity.collider, skeleton.grenade.entity.collider);

            var grenadeDirection = new CoreDirection(input.held.direction);

            if (grenadeDirection.IsEmptyHorizontal())
            {
                grenadeDirection = skeleton.body.direction;
            }

            grenadeDirection.Update(Direction2D.UP, true);
            grenadeDirection.Update(Direction2D.DOWN, false);

            skeleton.grenade.Launch(skeleton.body.entity.velocity, grenadeDirection);
        }
    }
Example #11
0
 public static bool IsOppositeVertical(CoreDirection lhs, CoreDirection rhs)
 {
     return((int)lhs.Vector.y + (int)rhs.Vector.y == 0);
 }
Example #12
0
 public CollisionState2D()
 {
     direction = new CoreDirection();
 }
Example #13
0
 public void Add(CoreDirection d)
 {
     Update(Flags |= d.Flags);
 }
Example #14
0
 public PlayerInput()
 {
     direction = new CoreDirection();
 }
Example #15
0
 public HandGrenadeInput()
 {
     direction = new CoreDirection();
 }
Example #16
0
 public CombatHandInput(CombatHandInput input)
 {
     direction = new CoreDirection(input.direction);
     grab      = input.grab;
 }
Example #17
0
 // Public static
 public static bool IsOppositeHorizontal(CoreDirection lhs, CoreDirection rhs)
 {
     return((int)lhs.Vector.x + (int)rhs.Vector.x == 0);
 }
Example #18
0
 public void Punch(CoreDirection d)
 {
     Debug.Log("punch");
     entity.SetVelocity(d.Vector * data.punchSpeed);
 }
Example #19
0
 public static bool IsSameHorizontal(CoreDirection lhs, CoreDirection rhs)
 {
     return((int)lhs.Vector.x == (int)rhs.Vector.x);
 }
Example #20
0
 public PlayerInput(PlayerInput input)
 {
     direction = new CoreDirection(input.direction);
     jump      = input.jump;
     crouch    = input.crouch;
 }
Example #21
0
 public static bool IsSameVertical(CoreDirection lhs, CoreDirection rhs)
 {
     return((int)lhs.Vector.y == (int)rhs.Vector.y);
 }
Example #22
0
 public HandGrenadeInput(HandGrenadeInput input)
 {
     direction = new CoreDirection(input.direction);
     launch    = input.launch;
 }
Example #23
0
 public CoreDirection(CoreDirection d)
 {
     Update(d);
 }
Example #24
0
 public CombatHandInput()
 {
     direction = new CoreDirection();
 }
Example #25
0
 public void Update(CoreDirection d)
 {
     Update(d.Vector);
 }