Question by
PopcornProYT · Aug 23, 2016 at 12:58 PM ·
rigidbody2dfreeze
i cant see the constrainst in rigidbody2d need help
i cant see the constrainst in rigidbody2d
Comment
this is my script by the way it is C# using UnityEngine; using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour {
public float moveSpeed;
public float jumpHeight;
float moveVelocity;
private bool grounded = false;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) ||
Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.UpArrow))
{
if (grounded)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
}
moveVelocity = 0;
//movement
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A) ||
Input.Get$$anonymous$$ey ($$anonymous$$eyCode.LeftArrow))
{
moveVelocity = -moveSpeed; //move left
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D) ||
Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
{
moveVelocity = moveSpeed; //move right
}
GetComponent<Rigidbody2D>().velocity = new Vector2(moveVelocity, GetComponent<Rigidbody2D>().velocity.y);
}
//check grounded
void OnTriggerEnter2D()
{
grounded = true;
}
void OnTriggerExit2D()
{
grounded = false;
}
}