Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2015
    Posts
    1

    Question 2D Platformer #11 - Problems with slope movement

    (I tried searching the forum for similar issues but didn't come up with anything. :/)

    My character is having issues going up steep slopes; he jitters and moves forward a tiny bit before heading back down again. Moving up a slope of, say, 15 degrees goes well, but 50 degrees and the issue above happens, even with the slope limit set to 75.

    Adding in something like
    Code:
    angle + 0.1f
    to
    Code:
    deltaMovement.y = Mathf.Abs(Mathf.Tan(angle * Mathf.Deg2Rad) * deltaMovement.x);
    allows him to go up in a "bumpy" manner but it's not as smooth as I'd want, nor do I think that's the right way to do it. Taking out
    Code:
    deltaMovement.x += IsGoingRight ? -SkinWidth  : SkinWidth;
    let's me move up and down at the same speed as the horizontal platforms but I'd like to solve the issue at hand.

    Debugging deltaMovement.x gets numbers like 0.006... or -0.002...; do I want those numbers to be higher?

    I thought I followed the steps the way Nelson laid out, but obviously something is wrong and I'm having difficulty figuring out how to solve the issue. So help would be appreciated, thanks and please let me know if more info is needed.

    Here's a gif of what's going on - http://i.imgur.com/EzoMF1B.gif - and my slope code is below:

    Code:
    private void HandleVerticalSlope(ref Vector2 deltaMovement)
    	{
    		
    		var center = (_raycastBottomLeft.x + _raycastBottomRight.x)/2;
    
    		
    		var direction = -Vector2.up;
    
    		
    		var slopeDistance = SlopeLimitTangent * (_raycastBottomRight.x - center);
    
    		
    		var slopeRayVector = new Vector2(center, _raycastBottomLeft.y);
    
    		
    		Debug.DrawRay(slopeRayVector, direction * slopeDistance, Color.green);
    
    		
    		var raycastHit = Physics2D.Raycast(slopeRayVector, direction, slopeDistance, PlatformMask);
    	
    		
    		if (!raycastHit) 
    			
    			return;
    
    		
    		var isMovingDownSlope = Mathf.Sign(raycastHit.normal.x) == Mathf.Sign(deltaMovement.x);
    
    		
    		if (!isMovingDownSlope)
    			
    			return;
    	
    		
    		var angle = Vector2.Angle(raycastHit.normal, Vector2.up);
    
    		
    		if (Mathf.Abs(angle) < .0001f)
    		{
    			Debug.Log("angle<.0001f");
    			
    			return;
    		}
    
    		
    		State.IsMovingDownSlope = true;
    
    		
    		State.SlopeAngle = angle;
    
    		
    		deltaMovement.y = raycastHit.point.y - slopeRayVector.y;
    	}
    
    	
    	private bool HandleHorizontalSlope(ref Vector2 deltaMovement, float angle, bool IsGoingRight)
    	{
    		
    		if (Mathf.RoundToInt(angle) == 90) 
    			
    			return false;
    
    		
    		if (angle > Parameters.SlopeLimit)
    		{
    			Debug.Log("slopeTooSteep");
    			deltaMovement.x = 0;
    
    			
    			return true;
    		}
    
    		
    		if (deltaMovement.y > 0.007f)
    		{ 
    			Debug.Log("slopeIsSlight");
    			
    			return true;
    		}
    		deltaMovement.x += IsGoingRight ? -SkinWidth  : SkinWidth;
    		
    		Debug.Log(deltaMovement.x);
    
    		deltaMovement.y = Mathf.Abs(Mathf.Tan(angle * Mathf.Deg2Rad) * deltaMovement.x);
    
    
    		State.IsMovingUpSlope = true;
    		State.IsCollidingBelow = true;
    
    		return true;
    	}

  2. #2
    Join Date
    Mar 2015
    Posts
    1
    Hi, I have the same problem. Did you manage to fix it?

    My character keep bouncing when it goes upslope, this looks bad and prevent it from jumping too, because when it bounces it's not grounded.
    Everything is fine and smooth when it goes downslope though.

    Also it has a problem at the beginning of the slope when it goes right, as soon as it touches the slope it stops, then it goes slowly in it until it is pushed back. This doesn't happen when it goes left.

    The slopes have a 30° angle, and the character has the same angle limit; if I increase the angle limit of the character, the problem persists and it looks even worst.

    Here's an image of the slopes:


    Ca anyone help me please or give me some tips please? Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •