Acceleration And Deceleration Help
So I'm trying to make my controls bit smoother for my fast paced 2D platformer, so I'm trying to make it where when you start moving there is a small build up till you get to your normal move speed, and you take some time to slowdown before you come to a stop, help would be appreciated, apologies, I'm still fairly new to game development!
The Whole Player Script:
Header ("ControllerInput")
public InputActionReference move;
public InputActionReference jumpAction;
public InputActionReference crouchAction;
public InputActionReference spinAction;
public InputActionReference bombAction;
public InputActionReference brakeAction;
public InputActionReference groundPoundAction;
public InputActionReference danceAction;
Header ("Particles")
public ParticleSystem danceParticle;
Header("Floats And Bools")
public float moveSpeed = 5f;
public float jumpForce = 3f;
public float wallJumpForce = 2f;
public float shortJumpMultiplier = 0.5f;
public float decelerationFactor = 0.1f;
public float minSpeed = 0.1f;
public bool canJump;
public bool spin;
public bool dive;
public bool slam;
public bool slamCancel;
public bool canWallBounce;
public bool bumped;
public bool rolling;
public bool landAnimation;
public bool facingLeft;
public bool freeMove;
public bool walk;
public bool blasted;
public bool dance;
public bool wallWalk;
public bool ceilingAbove;
public bool canDash = true;
public bool isDashing;
public bool jumpCanceled;
public bool canDiveBomb;
public bool diveBombed;
public bool spinDive;
Header("Dash Speeds")
public bool dash1;
public bool dash2;
public bool dash3;
public bool dash4;
Header("Dash Timer")
public float idleThreshold = 3f;
private float idleTime = 0f;
Header("Layers And Transforms")
public Transform groundCheck;
public Transform ceilingCheck;
public LayerMask groundLayer;
public LayerMask ceilingLayer;
Header("Private")
private Rigidbody2D playerRb;
private Animator playerAnim;
private Vector2 moveDirection;
private Vector2 lastDirection;
private bool isJumping;
private bool danceAir;
private float dashingTime = 0.25f;
SerializeField bool isBraking = false;
SerializeField bool crouching;
SerializeField Collider2D standingCollider;
SerializeField Collider2D crouchingCollider;
const float aboveCheckRadius = 0.2f;
void Start()
{
playerRb = GetComponent<Rigidbody2D>();
playerAnim = GetComponent<Animator>();
jumpAction.action.performed += JumpPerformed;
jumpAction.action.canceled += JumpCanceled;
crouchAction.action.performed += CrouchPerformed;
crouchAction.action.canceled += CrouchCanceled;
spinAction.action.performed += SpinPerformed;
brakeAction.action.performed += BrakePerformed;
groundPoundAction.action.performed += GroundPoundPerformed;
bombAction.action.performed += BombPerformed;
danceAction.action.performed += DancePerformed;
danceAction.action.canceled += DanceCanceled;
}
void OnDestroy()
{
// Unsubscribe to prevent memory leaks
jumpAction.action.performed -= JumpPerformed;
jumpAction.action.canceled -= JumpCanceled;
crouchAction.action.performed -= CrouchPerformed;
crouchAction.action.canceled -= CrouchCanceled;
spinAction.action.performed -= SpinPerformed;
brakeAction.action.performed
So I'm trying to make my controls bit smoother for my fast paced 2D platformer, so I'm trying to make it where when you start moving there is a small build up till you get to your normal move speed, and you take some time to slowdown before you come to a stop, help would be appreciated, apologies, I'm still fairly new to game development!
The Whole Player Script:
Header ("ControllerInput")
public InputActionReference move;
public InputActionReference jumpAction;
public InputActionReference crouchAction;
public InputActionReference spinAction;
public InputActionReference bombAction;
public InputActionReference brakeAction;
public InputActionReference groundPoundAction;
public InputActionReference danceAction;
Header ("Particles")
public ParticleSystem danceParticle;
Header("Floats And Bools")
public float moveSpeed = 5f;
public float jumpForce = 3f;
public float wallJumpForce = 2f;
public float shortJumpMultiplier = 0.5f;
public float decelerationFactor = 0.1f;
public float minSpeed = 0.1f;
public bool canJump;
public bool spin;
public bool dive;
public bool slam;
public bool slamCancel;
public bool canWallBounce;
public bool bumped;
public bool rolling;
public bool landAnimation;
public bool facingLeft;
public bool freeMove;
public bool walk;
public bool blasted;
public bool dance;
public bool wallWalk;
public bool ceilingAbove;
public bool canDash = true;
public bool isDashing;
public bool jumpCanceled;
public bool canDiveBomb;
public bool diveBombed;
public bool spinDive;
Header("Dash Speeds")
public bool dash1;
public bool dash2;
public bool dash3;
public bool dash4;
Header("Dash Timer")
public float idleThreshold = 3f;
private float idleTime = 0f;
Header("Layers And Transforms")
public Transform groundCheck;
public Transform ceilingCheck;
public LayerMask groundLayer;
public LayerMask ceilingLayer;
Header("Private")
private Rigidbody2D playerRb;
private Animator playerAnim;
private Vector2 moveDirection;
private Vector2 lastDirection;
private bool isJumping;
private bool danceAir;
private float dashingTime = 0.25f;
SerializeField bool isBraking = false;
SerializeField bool crouching;
SerializeField Collider2D standingCollider;
SerializeField Collider2D crouchingCollider;
const float aboveCheckRadius = 0.2f;
void Start()
{
playerRb = GetComponent<Rigidbody2D>();
playerAnim = GetComponent<Animator>();
jumpAction.action.performed += JumpPerformed;
jumpAction.action.canceled += JumpCanceled;
crouchAction.action.performed += CrouchPerformed;
crouchAction.action.canceled += CrouchCanceled;
spinAction.action.performed += SpinPerformed;
brakeAction.action.performed += BrakePerformed;
groundPoundAction.action.performed += GroundPoundPerformed;
bombAction.action.performed += BombPerformed;
danceAction.action.performed += DancePerformed;
danceAction.action.canceled += DanceCanceled;
}
void OnDestroy()
{
// Unsubscribe to prevent memory leaks
jumpAction.action.performed -= JumpPerformed;
jumpAction.action.canceled -= JumpCanceled;
crouchAction.action.performed -= CrouchPerformed;
crouchAction.action.canceled -= CrouchCanceled;
spinAction.action.performed -= SpinPerformed;
brakeAction.action.performed
-= BrakePerformed;
groundPoundAction.action.performed -= GroundPoundPerformed;
bombAction.action.performed -= BombPerformed;
danceAction.action.performed -= DancePerformed;
danceAction.action.canceled -= DanceCanceled;
}
void Update()
{
if (isDashing)
{
return;
}
#region MOVEMENT/JUMPING ANIMATIONS
float smoothedVelocityX = Mathf.Lerp(playerAnim.GetFloat("xVelocity"), Mathf.Abs(playerRb.velocity.x), Time.deltaTime 150f);
playerAnim.SetFloat("xVelocity", smoothedVelocityX);
if (wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", true);
spin = false;
}
else if (!wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", false);
}
if (!dance && isGrounded())
{
playerAnim.SetBool("Dance", false);
}
else if (dance && isGrounded() && !dash1)
{
playerAnim.SetBool("Dance", true);
}
if (isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", true);
danceAir = false;
}
else if (!isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", false);
danceAir = true;
}
bool isJumping = playerRb.velocity.y > 0.1f;
bool isFalling = playerRb.velocity.y < -0.1f;
if (!slam)
{
playerAnim.SetBool("Jump", isJumping);
if (!jumpCanceled)
{
playerAnim.SetBool("Fall", isFalling);
}
}
#endregion
#region WALK/DASH MOVEMENT
Flip();
if (!dive && !isBraking && !rolling && !walk && !dash4)
{
moveDirection = move.action.ReadValue<Vector2>();
}
if (isGrounded())
{
canJump = true;
canWallBounce = true;
slamCancel = false;
canDash = true;
jumpCanceled = false;
diveBombed = false;
spinDive = false;
playerAnim.SetBool("Fall", false);
playerAnim.SetBool("SlamCancel", false);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("Grounded", true);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(SlamFallAnimationEnd());
}
else
{
canJump = false;
}
if (!isGrounded())
{
playerAnim.SetBool("Grounded", false);
}
if(isGrounded() && isDashing)
{
isDashing = false;
}
if (!bumped && !dash1 && !isBraking)
{
moveSpeed = 9;
}
if (moveDirection.x == 0f && isGrounded() && !dash4)
{
idleTime += Time.deltaTime;
}
else
{
idleTime = 0f;
}
if (idleTime >= idleThreshold 4 && dash1 && isGrounded() && !dash4 && !bumped)
{
dash1 = false;
}
else if (idleTime >= idleThreshold 3 && dash2 && isGrounded() && !dash4 && !bumped)
{
dash2 = false;
}
else if (idleTime >= idleThreshold 2 && dash3 && isGrounded() && !dash4 && !bumped)
{
dash3 = false;
}
#endregion
#region DASH 4 MOVEMENT
if (!dive && !isBraking && !rolling && !bumped)
{
groundPoundAction.action.performed -= GroundPoundPerformed;
bombAction.action.performed -= BombPerformed;
danceAction.action.performed -= DancePerformed;
danceAction.action.canceled -= DanceCanceled;
}
void Update()
{
if (isDashing)
{
return;
}
#region MOVEMENT/JUMPING ANIMATIONS
float smoothedVelocityX = Mathf.Lerp(playerAnim.GetFloat("xVelocity"), Mathf.Abs(playerRb.velocity.x), Time.deltaTime 150f);
playerAnim.SetFloat("xVelocity", smoothedVelocityX);
if (wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", true);
spin = false;
}
else if (!wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", false);
}
if (!dance && isGrounded())
{
playerAnim.SetBool("Dance", false);
}
else if (dance && isGrounded() && !dash1)
{
playerAnim.SetBool("Dance", true);
}
if (isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", true);
danceAir = false;
}
else if (!isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", false);
danceAir = true;
}
bool isJumping = playerRb.velocity.y > 0.1f;
bool isFalling = playerRb.velocity.y < -0.1f;
if (!slam)
{
playerAnim.SetBool("Jump", isJumping);
if (!jumpCanceled)
{
playerAnim.SetBool("Fall", isFalling);
}
}
#endregion
#region WALK/DASH MOVEMENT
Flip();
if (!dive && !isBraking && !rolling && !walk && !dash4)
{
moveDirection = move.action.ReadValue<Vector2>();
}
if (isGrounded())
{
canJump = true;
canWallBounce = true;
slamCancel = false;
canDash = true;
jumpCanceled = false;
diveBombed = false;
spinDive = false;
playerAnim.SetBool("Fall", false);
playerAnim.SetBool("SlamCancel", false);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("Grounded", true);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(SlamFallAnimationEnd());
}
else
{
canJump = false;
}
if (!isGrounded())
{
playerAnim.SetBool("Grounded", false);
}
if(isGrounded() && isDashing)
{
isDashing = false;
}
if (!bumped && !dash1 && !isBraking)
{
moveSpeed = 9;
}
if (moveDirection.x == 0f && isGrounded() && !dash4)
{
idleTime += Time.deltaTime;
}
else
{
idleTime = 0f;
}
if (idleTime >= idleThreshold 4 && dash1 && isGrounded() && !dash4 && !bumped)
{
dash1 = false;
}
else if (idleTime >= idleThreshold 3 && dash2 && isGrounded() && !dash4 && !bumped)
{
dash2 = false;
}
else if (idleTime >= idleThreshold 2 && dash3 && isGrounded() && !dash4 && !bumped)
{
dash3 = false;
}
#endregion
#region DASH 4 MOVEMENT
if (!dive && !isBraking && !rolling && !bumped)
{
moveDirection = move.action.ReadValue<Vector2>();
if (dash4 && !freeMove)
{
if (moveDirection != Vector2.zero)
{
lastDirection = moveDirection;
walk = true;
}
else
{
moveDirection = lastDirection;
walk = false;
}
}
else
{
walk = false;
}
}
if (!dash4)
{
playerRb.velocity = new Vector2(moveDirection.x moveSpeed, playerRb.velocity.y);
}
else
{
playerRb.velocity = new Vector2(moveDirection.x moveSpeed, playerRb.velocity.y);
}
if(dash4 && isGrounded())
{
freeMove = false;
}
#endregion
#region BOMB SLAM
if (isGrounded() && slam && !slamCancel && dash4 && dash3 && dash2 && dash1 && !dance)
{
slam = false;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if(isGrounded() && slam && !slamCancel && dash3 && dash2 && dash1 && !dance)
{
slam = false;
dash4 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash2 && dash1 && !dance)
{
slam = false;
dash3 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash1 && !dance)
{
slam = false;
dash2 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && !dash1 && !dance)
{
slam = false;
dash1 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
#endregion
#region BRAKING/SPEED LOGIC
if (isBraking)
{
Dash1Deceleration();
}
else if (!isBraking)
{
if (dash4 && dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 21f;
}
else if (dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 18f;
}
else if (dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 15f;
}
else if (dash1 && !dive && !dance && !bumped)
{
moveSpeed = 12f;
}
else if (!dive &&
if (dash4 && !freeMove)
{
if (moveDirection != Vector2.zero)
{
lastDirection = moveDirection;
walk = true;
}
else
{
moveDirection = lastDirection;
walk = false;
}
}
else
{
walk = false;
}
}
if (!dash4)
{
playerRb.velocity = new Vector2(moveDirection.x moveSpeed, playerRb.velocity.y);
}
else
{
playerRb.velocity = new Vector2(moveDirection.x moveSpeed, playerRb.velocity.y);
}
if(dash4 && isGrounded())
{
freeMove = false;
}
#endregion
#region BOMB SLAM
if (isGrounded() && slam && !slamCancel && dash4 && dash3 && dash2 && dash1 && !dance)
{
slam = false;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if(isGrounded() && slam && !slamCancel && dash3 && dash2 && dash1 && !dance)
{
slam = false;
dash4 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash2 && dash1 && !dance)
{
slam = false;
dash3 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash1 && !dance)
{
slam = false;
dash2 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && !dash1 && !dance)
{
slam = false;
dash1 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
#endregion
#region BRAKING/SPEED LOGIC
if (isBraking)
{
Dash1Deceleration();
}
else if (!isBraking)
{
if (dash4 && dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 21f;
}
else if (dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 18f;
}
else if (dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 15f;
}
else if (dash1 && !dive && !dance && !bumped)
{
moveSpeed = 12f;
}
else if (!dive &&
!dance && !bumped)
{
moveSpeed = 9;
}
}
#endregion
}
private void FixedUpdate()
{
Crouch(crouching);
if (dive && isGrounded())
{
DiveDeceleration();
}
}
#region CONTROLS
void Flip()
{
if (playerRb.velocity.x < 0 && !facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = true;
transform.Rotate(0f, 180f, 0f);
}
else if (playerRb.velocity.x > 0 && facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = false;
transform.Rotate(0f, 180f, 0f);
}
}
private void JumpPerformed(InputAction.CallbackContext context)
{
if (canJump && !crouching && isGrounded() && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
}
else if(crouching && canJump && isGrounded() && playerRb.velocity.x == 0 && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, 8);
}
if (slam)
{
playerRb.velocity = new Vector2(0, 14);
playerRb.gravityScale = 3;
slam = false;
slamCancel = true;
freeMove = true;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamCancel", true);
}
#region DIVING
if (crouching && dash1 && dash2 && dash3 && dash4 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && dash3 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
}
#endregion
}
private void
{
moveSpeed = 9;
}
}
#endregion
}
private void FixedUpdate()
{
Crouch(crouching);
if (dive && isGrounded())
{
DiveDeceleration();
}
}
#region CONTROLS
void Flip()
{
if (playerRb.velocity.x < 0 && !facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = true;
transform.Rotate(0f, 180f, 0f);
}
else if (playerRb.velocity.x > 0 && facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = false;
transform.Rotate(0f, 180f, 0f);
}
}
private void JumpPerformed(InputAction.CallbackContext context)
{
if (canJump && !crouching && isGrounded() && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
}
else if(crouching && canJump && isGrounded() && playerRb.velocity.x == 0 && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, 8);
}
if (slam)
{
playerRb.velocity = new Vector2(0, 14);
playerRb.gravityScale = 3;
slam = false;
slamCancel = true;
freeMove = true;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamCancel", true);
}
#region DIVING
if (crouching && dash1 && dash2 && dash3 && dash4 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && dash3 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
}
#endregion
}
private void
Acceleration And Deceleration Help
So I'm trying to make my controls bit smoother for my fast paced 2D platformer, so I'm trying to make it where when you start moving there is a small build up till you get to your normal move speed, and you take some time to slowdown before you come to a stop, help would be appreciated, apologies, I'm still fairly new to game development!
The Whole Player Script:
[Header ("ControllerInput")]
public InputActionReference move;
public InputActionReference jumpAction;
public InputActionReference crouchAction;
public InputActionReference spinAction;
public InputActionReference bombAction;
public InputActionReference brakeAction;
public InputActionReference groundPoundAction;
public InputActionReference danceAction;
[Header ("Particles")]
public ParticleSystem danceParticle;
[Header("Floats And Bools")]
public float moveSpeed = 5f;
public float jumpForce = 3f;
public float wallJumpForce = 2f;
public float shortJumpMultiplier = 0.5f;
public float decelerationFactor = 0.1f;
public float minSpeed = 0.1f;
public bool canJump;
public bool spin;
public bool dive;
public bool slam;
public bool slamCancel;
public bool canWallBounce;
public bool bumped;
public bool rolling;
public bool landAnimation;
public bool facingLeft;
public bool freeMove;
public bool walk;
public bool blasted;
public bool dance;
public bool wallWalk;
public bool ceilingAbove;
public bool canDash = true;
public bool isDashing;
public bool jumpCanceled;
public bool canDiveBomb;
public bool diveBombed;
public bool spinDive;
[Header("Dash Speeds")]
public bool dash1;
public bool dash2;
public bool dash3;
public bool dash4;
[Header("Dash Timer")]
public float idleThreshold = 3f;
private float idleTime = 0f;
[Header("Layers And Transforms")]
public Transform groundCheck;
public Transform ceilingCheck;
public LayerMask groundLayer;
public LayerMask ceilingLayer;
[Header("Private")]
private Rigidbody2D playerRb;
private Animator playerAnim;
private Vector2 moveDirection;
private Vector2 lastDirection;
private bool isJumping;
private bool danceAir;
private float dashingTime = 0.25f;
[SerializeField] bool isBraking = false;
[SerializeField] bool crouching;
[SerializeField] Collider2D standingCollider;
[SerializeField] Collider2D crouchingCollider;
const float aboveCheckRadius = 0.2f;
void Start()
{
playerRb = GetComponent<Rigidbody2D>();
playerAnim = GetComponent<Animator>();
jumpAction.action.performed += JumpPerformed;
jumpAction.action.canceled += JumpCanceled;
crouchAction.action.performed += CrouchPerformed;
crouchAction.action.canceled += CrouchCanceled;
spinAction.action.performed += SpinPerformed;
brakeAction.action.performed += BrakePerformed;
groundPoundAction.action.performed += GroundPoundPerformed;
bombAction.action.performed += BombPerformed;
danceAction.action.performed += DancePerformed;
danceAction.action.canceled += DanceCanceled;
}
void OnDestroy()
{
// Unsubscribe to prevent memory leaks
jumpAction.action.performed -= JumpPerformed;
jumpAction.action.canceled -= JumpCanceled;
crouchAction.action.performed -= CrouchPerformed;
crouchAction.action.canceled -= CrouchCanceled;
spinAction.action.performed -= SpinPerformed;
brakeAction.action.performed
So I'm trying to make my controls bit smoother for my fast paced 2D platformer, so I'm trying to make it where when you start moving there is a small build up till you get to your normal move speed, and you take some time to slowdown before you come to a stop, help would be appreciated, apologies, I'm still fairly new to game development!
The Whole Player Script:
[Header ("ControllerInput")]
public InputActionReference move;
public InputActionReference jumpAction;
public InputActionReference crouchAction;
public InputActionReference spinAction;
public InputActionReference bombAction;
public InputActionReference brakeAction;
public InputActionReference groundPoundAction;
public InputActionReference danceAction;
[Header ("Particles")]
public ParticleSystem danceParticle;
[Header("Floats And Bools")]
public float moveSpeed = 5f;
public float jumpForce = 3f;
public float wallJumpForce = 2f;
public float shortJumpMultiplier = 0.5f;
public float decelerationFactor = 0.1f;
public float minSpeed = 0.1f;
public bool canJump;
public bool spin;
public bool dive;
public bool slam;
public bool slamCancel;
public bool canWallBounce;
public bool bumped;
public bool rolling;
public bool landAnimation;
public bool facingLeft;
public bool freeMove;
public bool walk;
public bool blasted;
public bool dance;
public bool wallWalk;
public bool ceilingAbove;
public bool canDash = true;
public bool isDashing;
public bool jumpCanceled;
public bool canDiveBomb;
public bool diveBombed;
public bool spinDive;
[Header("Dash Speeds")]
public bool dash1;
public bool dash2;
public bool dash3;
public bool dash4;
[Header("Dash Timer")]
public float idleThreshold = 3f;
private float idleTime = 0f;
[Header("Layers And Transforms")]
public Transform groundCheck;
public Transform ceilingCheck;
public LayerMask groundLayer;
public LayerMask ceilingLayer;
[Header("Private")]
private Rigidbody2D playerRb;
private Animator playerAnim;
private Vector2 moveDirection;
private Vector2 lastDirection;
private bool isJumping;
private bool danceAir;
private float dashingTime = 0.25f;
[SerializeField] bool isBraking = false;
[SerializeField] bool crouching;
[SerializeField] Collider2D standingCollider;
[SerializeField] Collider2D crouchingCollider;
const float aboveCheckRadius = 0.2f;
void Start()
{
playerRb = GetComponent<Rigidbody2D>();
playerAnim = GetComponent<Animator>();
jumpAction.action.performed += JumpPerformed;
jumpAction.action.canceled += JumpCanceled;
crouchAction.action.performed += CrouchPerformed;
crouchAction.action.canceled += CrouchCanceled;
spinAction.action.performed += SpinPerformed;
brakeAction.action.performed += BrakePerformed;
groundPoundAction.action.performed += GroundPoundPerformed;
bombAction.action.performed += BombPerformed;
danceAction.action.performed += DancePerformed;
danceAction.action.canceled += DanceCanceled;
}
void OnDestroy()
{
// Unsubscribe to prevent memory leaks
jumpAction.action.performed -= JumpPerformed;
jumpAction.action.canceled -= JumpCanceled;
crouchAction.action.performed -= CrouchPerformed;
crouchAction.action.canceled -= CrouchCanceled;
spinAction.action.performed -= SpinPerformed;
brakeAction.action.performed
-= BrakePerformed;
groundPoundAction.action.performed -= GroundPoundPerformed;
bombAction.action.performed -= BombPerformed;
danceAction.action.performed -= DancePerformed;
danceAction.action.canceled -= DanceCanceled;
}
void Update()
{
if (isDashing)
{
return;
}
#region MOVEMENT/JUMPING ANIMATIONS
float smoothedVelocityX = Mathf.Lerp(playerAnim.GetFloat("xVelocity"), Mathf.Abs(playerRb.velocity.x), Time.deltaTime * 150f);
playerAnim.SetFloat("xVelocity", smoothedVelocityX);
if (wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", true);
spin = false;
}
else if (!wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", false);
}
if (!dance && isGrounded())
{
playerAnim.SetBool("Dance", false);
}
else if (dance && isGrounded() && !dash1)
{
playerAnim.SetBool("Dance", true);
}
if (isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", true);
danceAir = false;
}
else if (!isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", false);
danceAir = true;
}
bool isJumping = playerRb.velocity.y > 0.1f;
bool isFalling = playerRb.velocity.y < -0.1f;
if (!slam)
{
playerAnim.SetBool("Jump", isJumping);
if (!jumpCanceled)
{
playerAnim.SetBool("Fall", isFalling);
}
}
#endregion
#region WALK/DASH MOVEMENT
Flip();
if (!dive && !isBraking && !rolling && !walk && !dash4)
{
moveDirection = move.action.ReadValue<Vector2>();
}
if (isGrounded())
{
canJump = true;
canWallBounce = true;
slamCancel = false;
canDash = true;
jumpCanceled = false;
diveBombed = false;
spinDive = false;
playerAnim.SetBool("Fall", false);
playerAnim.SetBool("SlamCancel", false);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("Grounded", true);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(SlamFallAnimationEnd());
}
else
{
canJump = false;
}
if (!isGrounded())
{
playerAnim.SetBool("Grounded", false);
}
if(isGrounded() && isDashing)
{
isDashing = false;
}
if (!bumped && !dash1 && !isBraking)
{
moveSpeed = 9;
}
if (moveDirection.x == 0f && isGrounded() && !dash4)
{
idleTime += Time.deltaTime;
}
else
{
idleTime = 0f;
}
if (idleTime >= idleThreshold * 4 && dash1 && isGrounded() && !dash4 && !bumped)
{
dash1 = false;
}
else if (idleTime >= idleThreshold * 3 && dash2 && isGrounded() && !dash4 && !bumped)
{
dash2 = false;
}
else if (idleTime >= idleThreshold * 2 && dash3 && isGrounded() && !dash4 && !bumped)
{
dash3 = false;
}
#endregion
#region DASH 4 MOVEMENT
if (!dive && !isBraking && !rolling && !bumped)
{
groundPoundAction.action.performed -= GroundPoundPerformed;
bombAction.action.performed -= BombPerformed;
danceAction.action.performed -= DancePerformed;
danceAction.action.canceled -= DanceCanceled;
}
void Update()
{
if (isDashing)
{
return;
}
#region MOVEMENT/JUMPING ANIMATIONS
float smoothedVelocityX = Mathf.Lerp(playerAnim.GetFloat("xVelocity"), Mathf.Abs(playerRb.velocity.x), Time.deltaTime * 150f);
playerAnim.SetFloat("xVelocity", smoothedVelocityX);
if (wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", true);
spin = false;
}
else if (!wallWalk && isGrounded())
{
playerAnim.SetBool("WallIdle", false);
}
if (!dance && isGrounded())
{
playerAnim.SetBool("Dance", false);
}
else if (dance && isGrounded() && !dash1)
{
playerAnim.SetBool("Dance", true);
}
if (isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", true);
danceAir = false;
}
else if (!isGrounded() && dance)
{
playerAnim.SetBool("DanceGround", false);
danceAir = true;
}
bool isJumping = playerRb.velocity.y > 0.1f;
bool isFalling = playerRb.velocity.y < -0.1f;
if (!slam)
{
playerAnim.SetBool("Jump", isJumping);
if (!jumpCanceled)
{
playerAnim.SetBool("Fall", isFalling);
}
}
#endregion
#region WALK/DASH MOVEMENT
Flip();
if (!dive && !isBraking && !rolling && !walk && !dash4)
{
moveDirection = move.action.ReadValue<Vector2>();
}
if (isGrounded())
{
canJump = true;
canWallBounce = true;
slamCancel = false;
canDash = true;
jumpCanceled = false;
diveBombed = false;
spinDive = false;
playerAnim.SetBool("Fall", false);
playerAnim.SetBool("SlamCancel", false);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("Grounded", true);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(SlamFallAnimationEnd());
}
else
{
canJump = false;
}
if (!isGrounded())
{
playerAnim.SetBool("Grounded", false);
}
if(isGrounded() && isDashing)
{
isDashing = false;
}
if (!bumped && !dash1 && !isBraking)
{
moveSpeed = 9;
}
if (moveDirection.x == 0f && isGrounded() && !dash4)
{
idleTime += Time.deltaTime;
}
else
{
idleTime = 0f;
}
if (idleTime >= idleThreshold * 4 && dash1 && isGrounded() && !dash4 && !bumped)
{
dash1 = false;
}
else if (idleTime >= idleThreshold * 3 && dash2 && isGrounded() && !dash4 && !bumped)
{
dash2 = false;
}
else if (idleTime >= idleThreshold * 2 && dash3 && isGrounded() && !dash4 && !bumped)
{
dash3 = false;
}
#endregion
#region DASH 4 MOVEMENT
if (!dive && !isBraking && !rolling && !bumped)
{
moveDirection = move.action.ReadValue<Vector2>();
if (dash4 && !freeMove)
{
if (moveDirection != Vector2.zero)
{
lastDirection = moveDirection;
walk = true;
}
else
{
moveDirection = lastDirection;
walk = false;
}
}
else
{
walk = false;
}
}
if (!dash4)
{
playerRb.velocity = new Vector2(moveDirection.x * moveSpeed, playerRb.velocity.y);
}
else
{
playerRb.velocity = new Vector2(moveDirection.x * moveSpeed, playerRb.velocity.y);
}
if(dash4 && isGrounded())
{
freeMove = false;
}
#endregion
#region BOMB SLAM
if (isGrounded() && slam && !slamCancel && dash4 && dash3 && dash2 && dash1 && !dance)
{
slam = false;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if(isGrounded() && slam && !slamCancel && dash3 && dash2 && dash1 && !dance)
{
slam = false;
dash4 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash2 && dash1 && !dance)
{
slam = false;
dash3 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash1 && !dance)
{
slam = false;
dash2 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && !dash1 && !dance)
{
slam = false;
dash1 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
#endregion
#region BRAKING/SPEED LOGIC
if (isBraking)
{
Dash1Deceleration();
}
else if (!isBraking)
{
if (dash4 && dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 21f;
}
else if (dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 18f;
}
else if (dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 15f;
}
else if (dash1 && !dive && !dance && !bumped)
{
moveSpeed = 12f;
}
else if (!dive &&
if (dash4 && !freeMove)
{
if (moveDirection != Vector2.zero)
{
lastDirection = moveDirection;
walk = true;
}
else
{
moveDirection = lastDirection;
walk = false;
}
}
else
{
walk = false;
}
}
if (!dash4)
{
playerRb.velocity = new Vector2(moveDirection.x * moveSpeed, playerRb.velocity.y);
}
else
{
playerRb.velocity = new Vector2(moveDirection.x * moveSpeed, playerRb.velocity.y);
}
if(dash4 && isGrounded())
{
freeMove = false;
}
#endregion
#region BOMB SLAM
if (isGrounded() && slam && !slamCancel && dash4 && dash3 && dash2 && dash1 && !dance)
{
slam = false;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if(isGrounded() && slam && !slamCancel && dash3 && dash2 && dash1 && !dance)
{
slam = false;
dash4 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash2 && dash1 && !dance)
{
slam = false;
dash3 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && dash1 && !dance)
{
slam = false;
dash2 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
else if (isGrounded() && slam && !slamCancel && !dash1 && !dance)
{
slam = false;
dash1 = true;
playerRb.gravityScale = 3;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamBlast", true);
blasted = true;
diveBombed = false;
playerRb.velocity = new Vector2(0, 19);
}
#endregion
#region BRAKING/SPEED LOGIC
if (isBraking)
{
Dash1Deceleration();
}
else if (!isBraking)
{
if (dash4 && dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 21f;
}
else if (dash3 && dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 18f;
}
else if (dash2 && dash1 && !dive && !dance && !bumped)
{
moveSpeed = 15f;
}
else if (dash1 && !dive && !dance && !bumped)
{
moveSpeed = 12f;
}
else if (!dive &&
!dance && !bumped)
{
moveSpeed = 9;
}
}
#endregion
}
private void FixedUpdate()
{
Crouch(crouching);
if (dive && isGrounded())
{
DiveDeceleration();
}
}
#region CONTROLS
void Flip()
{
if (playerRb.velocity.x < 0 && !facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = true;
transform.Rotate(0f, 180f, 0f);
}
else if (playerRb.velocity.x > 0 && facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = false;
transform.Rotate(0f, 180f, 0f);
}
}
private void JumpPerformed(InputAction.CallbackContext context)
{
if (canJump && !crouching && isGrounded() && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
}
else if(crouching && canJump && isGrounded() && playerRb.velocity.x == 0 && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, 8);
}
if (slam)
{
playerRb.velocity = new Vector2(0, 14);
playerRb.gravityScale = 3;
slam = false;
slamCancel = true;
freeMove = true;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamCancel", true);
}
#region DIVING
if (crouching && dash1 && dash2 && dash3 && dash4 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && dash3 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
}
#endregion
}
private void
{
moveSpeed = 9;
}
}
#endregion
}
private void FixedUpdate()
{
Crouch(crouching);
if (dive && isGrounded())
{
DiveDeceleration();
}
}
#region CONTROLS
void Flip()
{
if (playerRb.velocity.x < 0 && !facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = true;
transform.Rotate(0f, 180f, 0f);
}
else if (playerRb.velocity.x > 0 && facingLeft && !blasted && !danceAir && !bumped)
{
facingLeft = false;
transform.Rotate(0f, 180f, 0f);
}
}
private void JumpPerformed(InputAction.CallbackContext context)
{
if (canJump && !crouching && isGrounded() && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, jumpForce);
}
else if(crouching && canJump && isGrounded() && playerRb.velocity.x == 0 && !bumped && !isBraking)
{
isJumping = true;
canJump = false;
playerRb.velocity = new Vector2(playerRb.velocity.x, 8);
}
if (slam)
{
playerRb.velocity = new Vector2(0, 14);
playerRb.gravityScale = 3;
slam = false;
slamCancel = true;
freeMove = true;
playerAnim.SetBool("Slam", false);
playerAnim.SetBool("SlamCancel", true);
}
#region DIVING
if (crouching && dash1 && dash2 && dash3 && dash4 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 31;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && dash3 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 23;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && dash2 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 20;
playerRb.velocity = new Vector2(0, 6);
}
}
else if (crouching && dash1 && isGrounded() && canJump && !bumped)
{
if (playerRb.velocity.x > 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
else if (playerRb.velocity.x < 0)
{
dive = true;
moveSpeed = 18;
playerRb.velocity = new Vector2(0, 6);
}
}
#endregion
}
private void
JumpCanceled(InputAction.CallbackContext context)
{
jumpCanceled = true;
if (isJumping && canWallBounce && !bumped && !blasted)
{
if (playerRb.velocity.y > 0)
{
playerRb.velocity = new Vector2(playerRb.velocity.x, playerRb.velocity.y * shortJumpMultiplier);
}
isJumping = false;
}
}
private bool isGrounded()
{
return Physics2D.OverlapCapsule(groundCheck.position, new Vector2(0.5f, 0.1f), CapsuleDirection2D.Horizontal, 0, groundLayer);
}
private void BombPerformed(InputAction.CallbackContext context)
{
#region DIVEBOOST
if (canJump && dive && dash4 && dash3 && dash2 && dash1)
{
dive = false;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash3 && dash2 && dash1)
{
dive = false;
dash4 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash2 && dash1)
{
dive = false;
dash3 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash1)
{
dive = false;
dash2 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
#endregion
if (canDiveBomb && dash1 && dash2 && dash3 && dash4)
{
isDashing = false;
diveBombed = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && dash2 && dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash4 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash3 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && !dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash2 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && !dash1 && !dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash1 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
if (!isGrounded() && !slam && !slamCancel && !blasted && !dance && spinDive)
{
slam = true;
freeMove = true;
isDashing = false;
spinDive = false;
playerAnim.SetBool("Slam", true);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
playerRb.gravityScale = 2.5f;
playerRb.velocity = new Vector2(0, 9.5f);
{
jumpCanceled = true;
if (isJumping && canWallBounce && !bumped && !blasted)
{
if (playerRb.velocity.y > 0)
{
playerRb.velocity = new Vector2(playerRb.velocity.x, playerRb.velocity.y * shortJumpMultiplier);
}
isJumping = false;
}
}
private bool isGrounded()
{
return Physics2D.OverlapCapsule(groundCheck.position, new Vector2(0.5f, 0.1f), CapsuleDirection2D.Horizontal, 0, groundLayer);
}
private void BombPerformed(InputAction.CallbackContext context)
{
#region DIVEBOOST
if (canJump && dive && dash4 && dash3 && dash2 && dash1)
{
dive = false;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash3 && dash2 && dash1)
{
dive = false;
dash4 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash2 && dash1)
{
dive = false;
dash3 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
else if (canJump && dive && dash1)
{
dive = false;
dash2 = true;
playerRb.gravityScale = 3;
playerRb.velocity = new Vector2(0, 13);
}
#endregion
if (canDiveBomb && dash1 && dash2 && dash3 && dash4)
{
isDashing = false;
diveBombed = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && dash2 && dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash4 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash3 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && dash1 && !dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash2 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
else if (canDiveBomb && !dash1 && !dash2 && !dash3 && !dash4)
{
isDashing = false;
diveBombed = true;
dash1 = true;
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", true);
playerRb.velocity = new Vector2(0, 18);
}
if (!isGrounded() && !slam && !slamCancel && !blasted && !dance && spinDive)
{
slam = true;
freeMove = true;
isDashing = false;
spinDive = false;
playerAnim.SetBool("Slam", true);
playerAnim.SetBool("Dash", false);
playerAnim.SetBool("DashBlast", false);
playerAnim.SetBool("SpinDive", false);
playerRb.gravityScale = 2.5f;
playerRb.velocity = new Vector2(0, 9.5f);
StartCoroutine(SlamFall());
}
}
IEnumerator SlamFall()
{
yield return new WaitForSeconds(0.23f);
if (slam && !slamCancel)
{
playerRb.gravityScale = 5f;
}
}
IEnumerator SlamFallAnimationEnd()
{
yield return new WaitForSeconds(0.02f);
if (isGrounded())
{
playerAnim.SetBool("SlamBlast", false);
blasted = false;
}
}
private void DancePerformed(InputAction.CallbackContext context)
{
if (!dash1 && isGrounded() && !bumped)
{
dance = true;
danceParticle.Play();
}
}
private void DanceCanceled(InputAction.CallbackContext context)
{
dance = false;
danceAir = false;
danceParticle.Stop();
}
private void CrouchPerformed(InputAction.CallbackContext context)
{
if (isGrounded() && !dance && !bumped)
{
crouching = true;
spin = false;
playerAnim.SetBool("Crouch", true);
playerAnim.SetBool("Spin", false);
}
if (!slam && playerRb.velocity.x > 0 && crouching && dash1 && !bumped)
{
transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
rolling = true;
}
else if (!slam && playerRb.velocity.x < 0 && crouching && dash1)
{
transform.Translate(Vector2.left * moveSpeed * Time.deltaTime);
rolling = true;
}
if(!isGrounded() && !dance && !slam && !blasted)
{
playerRb.velocity = new Vector2(playerRb.velocity.x, -13f);
spinDive = true;
isDashing = false;
playerAnim.SetBool("SpinDive", true);
}
}
private void CrouchCanceled(InputAction.CallbackContext context)
{
crouching = false;
if (!slam && playerRb.velocity.x > 0 && dash1)
{
rolling = false;
}
else if (!slam && playerRb.velocity.x < 0 && dash1)
{
rolling = false;
}
}
void Crouch(bool crouchFlag)
{
if (!crouchFlag)
{
if (Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
crouchFlag = true;
}
}
if (!crouchFlag)
{
playerAnim.SetBool("Crouch", false);
rolling = false;
}
else
{
playerAnim.SetBool("Crouch", true);
}
standingCollider.enabled = !crouchFlag;
crouchingCollider.enabled = crouchFlag;
if (Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
ceilingAbove = true;
}
else if (!Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
StartCoroutine(AboveCheckStop());
}
}
IEnumerator AboveCheckStop()
{
yield return new WaitForSeconds(0.1f);
ceilingAbove = false;
}
private void DiveDeceleration()
{
if (moveSpeed > minSpeed)
{
moveSpeed -= decelerationFactor;
}
else
{
moveSpeed = 0;
dive = false;
}
}
private void SpinPerformed(InputAction.CallbackContext context)
{
if (!spin && !dive && !crouching && !slam && !slamCancel && canWallBounce && !dance && !bumped && !wallWalk && isGrounded())
}
}
IEnumerator SlamFall()
{
yield return new WaitForSeconds(0.23f);
if (slam && !slamCancel)
{
playerRb.gravityScale = 5f;
}
}
IEnumerator SlamFallAnimationEnd()
{
yield return new WaitForSeconds(0.02f);
if (isGrounded())
{
playerAnim.SetBool("SlamBlast", false);
blasted = false;
}
}
private void DancePerformed(InputAction.CallbackContext context)
{
if (!dash1 && isGrounded() && !bumped)
{
dance = true;
danceParticle.Play();
}
}
private void DanceCanceled(InputAction.CallbackContext context)
{
dance = false;
danceAir = false;
danceParticle.Stop();
}
private void CrouchPerformed(InputAction.CallbackContext context)
{
if (isGrounded() && !dance && !bumped)
{
crouching = true;
spin = false;
playerAnim.SetBool("Crouch", true);
playerAnim.SetBool("Spin", false);
}
if (!slam && playerRb.velocity.x > 0 && crouching && dash1 && !bumped)
{
transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
rolling = true;
}
else if (!slam && playerRb.velocity.x < 0 && crouching && dash1)
{
transform.Translate(Vector2.left * moveSpeed * Time.deltaTime);
rolling = true;
}
if(!isGrounded() && !dance && !slam && !blasted)
{
playerRb.velocity = new Vector2(playerRb.velocity.x, -13f);
spinDive = true;
isDashing = false;
playerAnim.SetBool("SpinDive", true);
}
}
private void CrouchCanceled(InputAction.CallbackContext context)
{
crouching = false;
if (!slam && playerRb.velocity.x > 0 && dash1)
{
rolling = false;
}
else if (!slam && playerRb.velocity.x < 0 && dash1)
{
rolling = false;
}
}
void Crouch(bool crouchFlag)
{
if (!crouchFlag)
{
if (Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
crouchFlag = true;
}
}
if (!crouchFlag)
{
playerAnim.SetBool("Crouch", false);
rolling = false;
}
else
{
playerAnim.SetBool("Crouch", true);
}
standingCollider.enabled = !crouchFlag;
crouchingCollider.enabled = crouchFlag;
if (Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
ceilingAbove = true;
}
else if (!Physics2D.OverlapCircle(ceilingCheck.position, aboveCheckRadius, ceilingLayer))
{
StartCoroutine(AboveCheckStop());
}
}
IEnumerator AboveCheckStop()
{
yield return new WaitForSeconds(0.1f);
ceilingAbove = false;
}
private void DiveDeceleration()
{
if (moveSpeed > minSpeed)
{
moveSpeed -= decelerationFactor;
}
else
{
moveSpeed = 0;
dive = false;
}
}
private void SpinPerformed(InputAction.CallbackContext context)
{
if (!spin && !dive && !crouching && !slam && !slamCancel && canWallBounce && !dance && !bumped && !wallWalk && isGrounded())
{
spin = true;
dash1 = true;
playerAnim.SetBool("Spin", true);
StartCoroutine(SpinCancel());
}
if(!isGrounded() && !spin && !dive && !crouching && !slamCancel && !dance && !bumped && !blasted && !wallWalk && canDash)
{
if (slam)
{
playerAnim.SetBool("Slam", false);
slam = false;
playerRb.gravityScale = 3;
}
playerAnim.SetBool("Dash", true);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(Dash());
}
}
IEnumerator SpinCancel()
{
yield return new WaitForSeconds(0.5f);
playerAnim.SetBool("Spin", false);
spin = false;
}
#region DASHSTUFF
IEnumerator Dash()
{
canDash = false;
spinDive = false;
isDashing = true;
canDiveBomb = true;
StartCoroutine(DiveBomb());
Vector2 originalVelocity = playerRb.velocity;
if (!facingLeft && !dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 19, 7f);
}
else if (facingLeft && !dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -19, 7f);
}
else if (!facingLeft && dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 21, 7f);
}
else if (facingLeft && dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -21, 7f);
}
else if (!facingLeft && dash1 && dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 25, 7f);
}
else if (facingLeft && dash1 && dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -25, 7f);
}
else if (!facingLeft && dash1 && dash2 && dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 28, 7f);
}
else if (facingLeft && dash1 && dash2 && dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -28, 7f);
}
else if (!facingLeft && dash1 && dash2 && dash3 && dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 31, 7f);
}
else if (facingLeft && dash1 && dash2 && dash3 && dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -31, 7f);
}
yield return new WaitForSeconds(dashingTime);
isDashing = false;
if (!isGrounded() && !slam && !slamCancel && !diveBombed && !spinDive)
{
float timeElapsed = 0f;
float slowdownDuration = 0.3f;
float startXVelocity = playerRb.velocity.x;
while (timeElapsed < slowdownDuration)
{
playerRb.velocity = new Vector2(Mathf.Lerp(startXVelocity, originalVelocity.x, timeElapsed / slowdownDuration), playerRb.velocity.y);
timeElapsed += Time.deltaTime;
yield return null;
}
playerRb.velocity = new Vector2(originalVelocity.x, playerRb.velocity.y);
}
else if(isGrounded() && isDashing)
{
isDashing = false;
}
}
IEnumerator DiveBomb()
{
yield return new WaitForSeconds(0.4f);
canDiveBomb = false;
}
#endregion
private void
spin = true;
dash1 = true;
playerAnim.SetBool("Spin", true);
StartCoroutine(SpinCancel());
}
if(!isGrounded() && !spin && !dive && !crouching && !slamCancel && !dance && !bumped && !blasted && !wallWalk && canDash)
{
if (slam)
{
playerAnim.SetBool("Slam", false);
slam = false;
playerRb.gravityScale = 3;
}
playerAnim.SetBool("Dash", true);
playerAnim.SetBool("SpinDive", false);
StartCoroutine(Dash());
}
}
IEnumerator SpinCancel()
{
yield return new WaitForSeconds(0.5f);
playerAnim.SetBool("Spin", false);
spin = false;
}
#region DASHSTUFF
IEnumerator Dash()
{
canDash = false;
spinDive = false;
isDashing = true;
canDiveBomb = true;
StartCoroutine(DiveBomb());
Vector2 originalVelocity = playerRb.velocity;
if (!facingLeft && !dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 19, 7f);
}
else if (facingLeft && !dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -19, 7f);
}
else if (!facingLeft && dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 21, 7f);
}
else if (facingLeft && dash1 && !dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -21, 7f);
}
else if (!facingLeft && dash1 && dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 25, 7f);
}
else if (facingLeft && dash1 && dash2 && !dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -25, 7f);
}
else if (!facingLeft && dash1 && dash2 && dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 28, 7f);
}
else if (facingLeft && dash1 && dash2 && dash3 && !dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -28, 7f);
}
else if (!facingLeft && dash1 && dash2 && dash3 && dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * 31, 7f);
}
else if (facingLeft && dash1 && dash2 && dash3 && dash4)
{
playerRb.velocity = new Vector2(transform.localScale.x * -31, 7f);
}
yield return new WaitForSeconds(dashingTime);
isDashing = false;
if (!isGrounded() && !slam && !slamCancel && !diveBombed && !spinDive)
{
float timeElapsed = 0f;
float slowdownDuration = 0.3f;
float startXVelocity = playerRb.velocity.x;
while (timeElapsed < slowdownDuration)
{
playerRb.velocity = new Vector2(Mathf.Lerp(startXVelocity, originalVelocity.x, timeElapsed / slowdownDuration), playerRb.velocity.y);
timeElapsed += Time.deltaTime;
yield return null;
}
playerRb.velocity = new Vector2(originalVelocity.x, playerRb.velocity.y);
}
else if(isGrounded() && isDashing)
{
isDashing = false;
}
}
IEnumerator DiveBomb()
{
yield return new WaitForSeconds(0.4f);
canDiveBomb = false;
}
#endregion
private void
BrakePerformed(InputAction.CallbackContext context)
{
if (playerRb.velocity.x > 0 && !isBraking && !dive && !crouching && !dance && isGrounded() && !bumped && !wallWalk)
{
isBraking = true;
dash1 = false;
playerAnim.SetBool("Brake", true);
}
else if (playerRb.velocity.x < 0 && !isBraking && !dive && !crouching && !dance && isGrounded() && !bumped && !wallWalk)
{
isBraking = true;
dash1 = false;
playerAnim.SetBool("Brake", true);
}
}
private void Dash1Deceleration()
{
if (moveSpeed > 0)
{
moveSpeed -= decelerationFactor * 25f * Time.deltaTime; // Decrease speed gradually
moveSpeed = Mathf.Max(moveSpeed, 0); // Clamp speed
}
else
{
moveSpeed = 0;
isBraking = false;
dash1 = false;
dash2 = false;
dash3 = false;
dash4 = false;
playerAnim.SetBool("Brake", false);
}
}
#endregion
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall") && !isGrounded() && canWallBounce && !slam && dash1 && !bumped)
{
playerRb.velocity = new Vector2(0f, 18f);
canWallBounce = false;
dive = false;
canJump = false;
freeMove = true;
}
if (collision.gameObject.CompareTag("Wall") && dash1 && isGrounded() && canJump && !ceilingAbove || collision.gameObject.layer == 6 && dash1 && isGrounded() && canJump && !ceilingAbove)
{
moveSpeed = 0;
bumped = true;
crouching = false;
playerAnim.SetBool("Bump", true);
StartCoroutine(WallDeceleration());
}
if(collision.gameObject.CompareTag("Wall") && !dash1 && isGrounded() && !ceilingAbove || collision.gameObject.layer == 6 && !dash1 && isGrounded() && !ceilingAbove)
{
wallWalk = true;
isBraking = false;
playerAnim.SetBool("Brake", false);
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall") && !bumped && isGrounded() || collision.gameObject.layer == 6 && !bumped && isGrounded())
{
wallWalk = false;
}
}
IEnumerator WallDeceleration()
{
yield return new WaitForSeconds(0.40f);
moveSpeed = 7;
dash1 = false;
dash2 = false;
dash3 = false;
dash4 = false;
bumped = false;
playerAnim.SetBool("Bump", false);
}
https://redd.it/1i11lf8
@r_Unity3D
{
if (playerRb.velocity.x > 0 && !isBraking && !dive && !crouching && !dance && isGrounded() && !bumped && !wallWalk)
{
isBraking = true;
dash1 = false;
playerAnim.SetBool("Brake", true);
}
else if (playerRb.velocity.x < 0 && !isBraking && !dive && !crouching && !dance && isGrounded() && !bumped && !wallWalk)
{
isBraking = true;
dash1 = false;
playerAnim.SetBool("Brake", true);
}
}
private void Dash1Deceleration()
{
if (moveSpeed > 0)
{
moveSpeed -= decelerationFactor * 25f * Time.deltaTime; // Decrease speed gradually
moveSpeed = Mathf.Max(moveSpeed, 0); // Clamp speed
}
else
{
moveSpeed = 0;
isBraking = false;
dash1 = false;
dash2 = false;
dash3 = false;
dash4 = false;
playerAnim.SetBool("Brake", false);
}
}
#endregion
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall") && !isGrounded() && canWallBounce && !slam && dash1 && !bumped)
{
playerRb.velocity = new Vector2(0f, 18f);
canWallBounce = false;
dive = false;
canJump = false;
freeMove = true;
}
if (collision.gameObject.CompareTag("Wall") && dash1 && isGrounded() && canJump && !ceilingAbove || collision.gameObject.layer == 6 && dash1 && isGrounded() && canJump && !ceilingAbove)
{
moveSpeed = 0;
bumped = true;
crouching = false;
playerAnim.SetBool("Bump", true);
StartCoroutine(WallDeceleration());
}
if(collision.gameObject.CompareTag("Wall") && !dash1 && isGrounded() && !ceilingAbove || collision.gameObject.layer == 6 && !dash1 && isGrounded() && !ceilingAbove)
{
wallWalk = true;
isBraking = false;
playerAnim.SetBool("Brake", false);
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall") && !bumped && isGrounded() || collision.gameObject.layer == 6 && !bumped && isGrounded())
{
wallWalk = false;
}
}
IEnumerator WallDeceleration()
{
yield return new WaitForSeconds(0.40f);
moveSpeed = 7;
dash1 = false;
dash2 = false;
dash3 = false;
dash4 = false;
bumped = false;
playerAnim.SetBool("Bump", false);
}
https://redd.it/1i11lf8
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Put a slow down enemy movement feature
Does any know how or a video on how to add a game object that slows down the enemy speed only for a moment?
https://redd.it/1i13tff
@r_Unity3D
Does any know how or a video on how to add a game object that slows down the enemy speed only for a moment?
https://redd.it/1i13tff
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Unity 6 – ready to use, or too early. Discuss?
Has anyone upgraded to Unity 6? If so, have you had any issues? Have you explored features like the UI Toolkit, Unity Sentis, or the new lighting? I started learning on a previous version of Unity and am now trying to decide which version to use when I begin prototyping my games.
https://redd.it/1i1555g
@r_Unity3D
Has anyone upgraded to Unity 6? If so, have you had any issues? Have you explored features like the UI Toolkit, Unity Sentis, or the new lighting? I started learning on a previous version of Unity and am now trying to decide which version to use when I begin prototyping my games.
https://redd.it/1i1555g
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
I want feedback on my first ever game! (Free, Itch)
https://0xyboxy.itch.io/survive-the-arena-sta
https://redd.it/1i16efo
@r_Unity3D
https://0xyboxy.itch.io/survive-the-arena-sta
https://redd.it/1i16efo
@r_Unity3D
itch.io
Survive The Arena - STA by 0xyBoxy
Available for Windows, macOS, Linux
How to Create a Shader for Stretching a 2D Sprite Based on Cursor or Touch Movement?
Hi everyone,
I’m trying to create a shader for a 2D Sprite Renderer that stretches the sprite based on the direction of mouse cursor movement or touch gestures on the screen.
Here’s the functionality I’m aiming for:
When the user interacts with the sprite by touching or clicking within its collider (e.g., at point A (1, 0, 0)) and moves their hand or cursor to point B (3, 0, 0), the sprite should stretch in the direction of vector AB.
This stretching behavior should work for any direction in which the user moves their gesture.
I have some experience with creating shaders, but my attempts so far haven’t produced the desired results.
If anyone has encountered a similar problem, I would greatly appreciate your help. Specifically, if you could share guidance, examples, or keywords I can use to research this further, it would be really helpful.
Thank you in advance!
https://preview.redd.it/7v6gmm6mozce1.png?width=1920&format=png&auto=webp&s=5045df7ab814a1c0b749f387732c1430443a2267
https://redd.it/1i1agtr
@r_Unity3D
Hi everyone,
I’m trying to create a shader for a 2D Sprite Renderer that stretches the sprite based on the direction of mouse cursor movement or touch gestures on the screen.
Here’s the functionality I’m aiming for:
When the user interacts with the sprite by touching or clicking within its collider (e.g., at point A (1, 0, 0)) and moves their hand or cursor to point B (3, 0, 0), the sprite should stretch in the direction of vector AB.
This stretching behavior should work for any direction in which the user moves their gesture.
I have some experience with creating shaders, but my attempts so far haven’t produced the desired results.
If anyone has encountered a similar problem, I would greatly appreciate your help. Specifically, if you could share guidance, examples, or keywords I can use to research this further, it would be really helpful.
Thank you in advance!
https://preview.redd.it/7v6gmm6mozce1.png?width=1920&format=png&auto=webp&s=5045df7ab814a1c0b749f387732c1430443a2267
https://redd.it/1i1agtr
@r_Unity3D
Comparing How Crystal Arts Change the Way You Navigate an Area
https://youtu.be/-gZerBUDeAU?si=zzSxk9JBuuZuA9H7
https://redd.it/1i1bniu
@r_Unity3D
https://youtu.be/-gZerBUDeAU?si=zzSxk9JBuuZuA9H7
https://redd.it/1i1bniu
@r_Unity3D
YouTube
Comparing How Differently You Navigate an Area with the Proper Crystal Art!
A look at how much of a difference having the right Crystal Art can be!
Every biome in LUCID will introduce new mechanics and obstacles that revolve around the Crystal Art you find there.
I try to design rooms to have multiple routes for the different Crystal…
Every biome in LUCID will introduce new mechanics and obstacles that revolve around the Crystal Art you find there.
I try to design rooms to have multiple routes for the different Crystal…
Duplicating a prefab but the animation stays for all
I’ve duplicated a prefab but want to change the animation state attached to each individually. How? Is it possible?
https://redd.it/1i1d6l9
@r_Unity3D
I’ve duplicated a prefab but want to change the animation state attached to each individually. How? Is it possible?
https://redd.it/1i1d6l9
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
This media is not supported in your browser
VIEW IN TELEGRAM
Trying to find visual identity for my weird horror game, really digging this look
https://redd.it/1i1895s
@r_Unity3D
https://redd.it/1i1895s
@r_Unity3D