I really want to begin making 2d platformer games and i know all the basics.
Right now i want my player to move, but i don’t know how to do it? Do anyone know any tutorials or something?
When i move object i use
transform.Translate(Vector3(x.x.x) * Time.deltaTime);
But as far as i know its not a good idea to use translate.
So for a conclusion: How can i make my player move and jump in javascript?
I don’t know how many posts there has been about player movement but it has not been possible for to find any posts.
Just tried it and it works. But when i collide with colliders it repeatly goes a little bit into the collider and then goes back out of the collider.
the player " lags" when i walk into a colider.
I assume that other people also have had this problem. how do you do that?
You could probably fix that issue by adding some raycasts or linecasts on each side of your character to see if there is something in the way. If the raycast hits something then don’t move him in that direction.
While we don’t include the full game demo in the package, we do include all the scripts etc. We can’t include the full demo because the models were from the asset store. However, check it out and see if the movement is what you’re looking for?
You need to use rigidbody2D.AddForce(x,y);
(add a rigidbody2D component to the character as well).
You can use that function to add forces in the directions you want to go under whatever conditions you want, like an if(keypress) type statement.
Moving your character this way will respect collision detection without anything else needed. It should be used within FixedUpdate(), not Update(). Anything affecting physics should be used in FixedUpdate().
You can also use rigidbody2D.velocity = new Vector2(x,y); to set an absolute velocity for the movement, for instant full speed, or use it to check the current velocity and tell your script to stop allowing more AddVelocity if you’ve reached a certain rigidbody2D.velocity.
If you want to use translate on a physics rigidbody then use Rigidbody2d.MovePosition instead because transform.translate does exactly the thing you described. If your player was too fast it might even just clip through the wall.
Also make sure to put anything related to pysics into FixedUpdate() instead of just Update().
(edit) aaaaand I just realized that this thread was ressurected all the way back from January.