public void Update(CollisionState2D s) { direction = s.direction; becameGroundedThisFrame = s.becameGroundedThisFrame; movingDownSlope = s.movingDownSlope; slopeAngle = s.slopeAngle; }
public EnemyMotor(PhysicsEntity e, Transform t) : base(e, t) { targetDirection = new CoreDirection(Direction2D.RIGHT); FrameCounter.Instance.OnUpdate += HandleUpdate; }
public CoreDirection GetInputPressed(CoreDirection oldInput, CoreDirection newInput) { var result = new CoreDirection(); var prime = GetInputPressed(oldInput.Vector, newInput.Vector); result.Update(prime); return(result); }
// 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); }
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"); }
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; }
// 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]); }
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); }
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); }
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); } }
public static bool IsOppositeVertical(CoreDirection lhs, CoreDirection rhs) { return((int)lhs.Vector.y + (int)rhs.Vector.y == 0); }
public CollisionState2D() { direction = new CoreDirection(); }
public void Add(CoreDirection d) { Update(Flags |= d.Flags); }
public PlayerInput() { direction = new CoreDirection(); }
public HandGrenadeInput() { direction = new CoreDirection(); }
public CombatHandInput(CombatHandInput input) { direction = new CoreDirection(input.direction); grab = input.grab; }
// Public static public static bool IsOppositeHorizontal(CoreDirection lhs, CoreDirection rhs) { return((int)lhs.Vector.x + (int)rhs.Vector.x == 0); }
public void Punch(CoreDirection d) { Debug.Log("punch"); entity.SetVelocity(d.Vector * data.punchSpeed); }
public static bool IsSameHorizontal(CoreDirection lhs, CoreDirection rhs) { return((int)lhs.Vector.x == (int)rhs.Vector.x); }
public PlayerInput(PlayerInput input) { direction = new CoreDirection(input.direction); jump = input.jump; crouch = input.crouch; }
public static bool IsSameVertical(CoreDirection lhs, CoreDirection rhs) { return((int)lhs.Vector.y == (int)rhs.Vector.y); }
public HandGrenadeInput(HandGrenadeInput input) { direction = new CoreDirection(input.direction); launch = input.launch; }
public CoreDirection(CoreDirection d) { Update(d); }
public CombatHandInput() { direction = new CoreDirection(); }
public void Update(CoreDirection d) { Update(d.Vector); }