Smooth Slide

Hi!

Another artist trying to broaden his horizon here, so bear with me. Last few days I’ve been cobbling together a movement script for a 2D-sidescroller:

I’ve been trying to add a new move to the basic moveset - a slide that will propel the player for x meters and then come to a halt, rapidly but also smooth-like.

I tried to use SmoothDamp but couldn’t wrap my head around it. Attempted to use a Lerp instead, which was a half-success. It moves the CharacterController, but does so instantly.

Not sure what to look at, would appreciate some pointers.

public mySpeed as single = 6.0F
public myJumpspeed as single = 8.0F
public myGravity as single = 20.0F
public myAirModifier as single = 0.5F

public mySlideLength as single = 1.0F //Modifier of mySpeed.

private myDirection as Vector3
private myController as CharacterController	
private myTransform as Transform	

private gonnaSlide as bool = false

private timesinceSlide as single
public slideCooldown as single = 1.0F

private smoothSlide as single = 5.0
private mySlideLerp as Vector3

private def Update():

	myController = GetComponent[of CharacterController]()
	myTransform = transform
			
	myX as single = Input.GetAxis('Horizontal')
	
	
	
	if myController.isGrounded:
		myDirection = Vector3((myX), 0, 0)
		myDirection = (myTransform.TransformDirection(myDirection) * mySpeed)
		
		if Input.GetButtonUp('Jump'):
			myDirection.y = myJumpspeed

My probably misguided attempt below VV

		if Input.GetButtonUp('Fire1') and (Time.time > timesinceSlide) and (myController.velocity.x != 0): //Allow slide if enough time has passed since last slide.
			
			timesinceSlide = (Time.time + slideCooldown)
		
			myEndpos as Vector3 = Vector3((myDirection.x * mySlideLength), 0, 0)				
			mySlideLerp = Vector3.Lerp(myDirection, myEndpos, (Time.deltaTime * smoothSlide))
			
			gonnaSlide = true
			
	else:
		myDirection.x = (((myX) * mySpeed) * myAirModifier)
		myDirection = myTransform.TransformDirection(myDirection)
		
	// Apply gravity.
	myDirection.y -= (myGravity * Time.deltaTime)		

And move

	if gonnaSlide is true:
		myController.Move(mySlideLerp)
		
	else:
		myController.Move(myDirection * Time.deltaTime)
		
	gonnaSlide = false

Thank you for the effort!

Unfortunately, neither method worked. I wonder if it’s to do with how Move works. I’ll keep trying!