Rigidbody.velocity.y Problem

Hi, I’m trying to make a game in which you can flip the player so it moves to the top of the screen and then back down again, in order to avoid obstacles. Now, when the player is at the bottom of the screen, the jumping works perfectly but when at the top of the screen, it just doesn’t work :frowning:

var Player : GameObject;
var Player1 : Transform;
var JumpHeight : int;
var isGrounded : boolean;
var Flipped : boolean = false;
var FirstPosition : Vector2;
var LastPosition : Vector2;

function Start()
{
	Physics2D.gravity = Vector2(0, -50);
}

function Update()
{
	var rb = Player.GetComponent.<Rigidbody2D>();
	rb.velocity.x = 7;
	for (var touch : Touch in Input.touches)
	{
		  if(touch.phase == TouchPhase.Began)
		  { 
		  	FirstPosition = touch.position;
		  	LastPosition = touch.position;
		  }
		  if(touch.phase == TouchPhase.Moved)
		  {
		  	LastPosition = touch.position;
		  }
		  if(touch.phase == TouchPhase.Ended)
		  {
		  	if((LastPosition.y - FirstPosition.y) > 2 && Flipped == false)
		  	{
		  	    Flipped = true;
				Physics2D.gravity = Vector2(0, 50);
				Player1.Rotate(180,0,0);
			}
		    if((LastPosition.y - FirstPosition.y) < -2 && Flipped == true)
		  	{
		  		Flipped = false;
				Physics2D.gravity = Vector2(0, -50);
				Player1.Rotate(0,0,0);
		  	}
		    if(LastPosition.y == FirstPosition.y && Flipped == true)
		  	{
		  		rb.velocity.y = -JumpHeight;	
		  	}
		  	if(LastPosition.y == FirstPosition.y);
		  	{
				rb.velocity.y = JumpHeight;
			}
		  }
	}
}

So yeah, I’m trying to get the player to be able to jump downwards if it has been flipped

Thanks :slight_smile:

(The line in question is number 45)

add on line 47 “&& Flipped == false” because both if on line 43 and 47 true and conflict