Limit movements on screen

I’m trying to make my character not leave the screen, putting a limit value left and right. But this value is varying a little making it pass the screen and I do not know why.
Could you please help me?
Thank you so much.

Follow the code:

Var SJogador = pc.createScript (‘sGamer’);
Var speed = 3;

// initialize code called once per entity
Splay.prototype.initialize = function () {

};

// update code called every frame
SJogador.prototype.update = function (dt) {

 If (this.app.keyboard.isPressed (pc.KEY_LEFT) & this.entity.position.x> = -4.1) {
     This.entity.translate (- speed * dt, 0,0);
 }

 If (this.app.keyboard.isPressed (pc.KEY_RIGHT) & this.entity.position.x <= 4.1) {
     This.entity.translate (speed * dt, 0,0);
 }

};

Please use Code Highlight button to make your code to look good.

You need to do it differently, by checking if your player after movement is too far, then reposition it accordingly.

As well ?
Could you explain me please

Questions you ask are due to lack of general knowledge in development. Development - is not easy job, you need to be determined, and work hard. It is a lot of investigation and learning to think like developer. Don’t rush this process, you need to learn how to learn - this is most important skill.
Asking every single task on forum - will not help you much, because you need to be able to solve such problems yourself.

Look at other projects to learn, and feel free to experiment.
Good place to start are tutorials: http://developer.playcanvas.com/en/tutorials/

It’s because I came from Unity3d and I’m not yet accustomed to PlayCanvas.

Question you’ve asked is not relevant to specific engine, it is generic to gamedev.

You’re right…
I was a long time away from programming and I lost practice …
I wanted to at least have a base to start over and start creating my own codes …

I have already researched the tutorials but I can not find anything like a simple 2d platform game … With jump, gravity and etc … The closest is the Flappy Bird however there is no jump system …

Here is Platformer example: https://playcanvas.com/project/1112/overview/starter-kit-platformer