Hey guys … ive been reading JavaScript and Unity Tutorials for a week now aiming to someday be able to make my own Epic 2d Game …
I learned the basic idea of Character Moving and jumping and it really worked on a plane and a cube project or a Cube over a Cube project and everything is really smooth .
i spent the whole night trying to figure how to make that with 2D objects … Like i draw a background and a character and i’m trying to make him walking on the ground but whenever i play the project the character falls down throw the Y dimension .
I’m Using this Code :
#pragma strict
var walkspeed: float = 5.0;
var jumpheight: float = 250.0;
var grounded = false;
function Start() {
}
function Update() {
rigidbody.freezeRotation = true;
if (Input.GetKey("a")) transform.Translate(Vector3(-1, 0, 0) * Time.deltaTime * walkspeed);
if (Input.GetKey("d")) transform.Translate(Vector3(1, 0, 0) * Time.deltaTime * walkspeed);
if (Input.GetButton("Jump")) {
Jump();
}
}
function OnCollisionEnter(hit: Collision) {
grounded = true;
}
function Jump() {
if (grounded == true) {
rigidbody.AddForce(Vector3.up * jumpheight);
grounded = false;
}
}
I thought that the problem was that i dont have a plane so actually the character could find something to stand on but even if i added one its the same issue … the character falls throw the plane , FYI i added the component Rigibody to the character in order to work with the gravity … am I missing something guys ?
thank u all