About 'Move Player Horizontally'!

Not the 4.6 but the other one

1 Like

Never mind I Did not Import it correctly

I think I need some sleep To much behind the computer doing all this stuff !
Sorry for wasting your time

1 Like

No worries and it’s not a waste of my time :slight_smile:

Glad you have managed to resolve the issue yourself, well done :slight_smile:

Hi Rick! I’m using unity 2018.3.0f2 and there’s no crossplatforminput to import. What should I do? Kinda getting crazy because of that. ahuaa
Please, tell me is already in the unity 2018. huhu

Resolved here : Not finding the Crossplatforminput in my unity 2018.3.0f2

Hi when I built my run() method I used transform.position rather than RigidBody
why are we moving RigidBody over transform.position?

private void run()
{

var deltaX = CrossPlatformInputManager.GetAxis("Horizontal") * Time.deltaTime * runSpeed;
var deltaY = CrossPlatformInputManager.GetAxis("Vertical") * Time.deltaTime * JumpHeight;
if(deltaX>0)
{
    GetComponent<Animator>().SetBool("Running", true);
    this.GetComponent<SpriteRenderer>().flipX = true;
}
else if (deltaX <0)
{
    GetComponent<Animator>().SetBool("Running", true);
    this.GetComponent<SpriteRenderer>().flipX = false;
}
else
{
    GetComponent<Animator>().SetBool("Running", false);
}

// move by transform
var newPosX = transform.position.x + deltaX;
var newPosY = transform.position.y + deltaY;
transform.position = new Vector2(newPosX, newPosY);

// move by rigidbody
/*Vector2 PlayerMovement = new Vector2(deltaX * runSpeed, deltaY * JumpHeight);
myRigidBody.velocity = PlayerMovement;*/

}

Hi James,

I’m not an instructor, but I’ll give a shot at answering.

My understanding is that, moving the player by moving the transform allows it to go through colliders. When I was trying to get the Run() method working, I tried to use transform.translate and I was having the problem of my player moving through colliders. Moving the player by giving velocity to the Rigidbody2D allows the physics (e.g. collisions) to work. Someone more knowledgeable please step in here and correct me if I’m horribly wrong!

Secondly I wanted to mention Input.GetAxisRaw, which is like Input.GetAxis, but returns -1 or 1 immediately rather than having a ramp-up time. This stops your player sliding after you have stopped pressing the move keys, and you don’t have to play around with the sensitivity variable like Rick was doing in the last 30s of the video.

The link that you provided is now empty, Sir. I tried to find it on the asset store with similar options, but I couldn’t find anything. Any link or something so I can download a similar thing?

Privacy & Terms