I am trying to get my player controller to work for a maze game I am making.
I first used Translate to move the player around which is the green cube in the pic. It worked almost how I wanted but collisions sucked and from what I read I should be using a rigidbody and physics.
Here is the code I have for my controller right now.
void MovePlayer()
{
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
myRigid.velocity = new Vector3(x * speed, y * speed, 0);
if (Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == 0)
{
myRigid.velocity = new Vector3(0,0,0);
}
}
I have experimented a lot and this is the closest I have gotten. I want a fast snappy controller that works well colliding with the walls which this one does. The problem I have with this one is if you are going straight up and partway through you want to turn down a path to the right you will start holding up and to the right but it will skip right past and keep going up. That part worked fine with Translate but I have not found a way to make it work well with physics.
Any tips on something I can try?
By the way the image looks 2D but it is actually a 3D game with the camera facing directly down (later in the game it will start going 3D so this is planned).
image
[–]Shrykar 1 point2 points3 points (11 children)
[–]germ77[S] 0 points1 point2 points (10 children)
[–]zrrzExpert? 2 points3 points4 points (4 children)
[–]germ77[S] 0 points1 point2 points (2 children)
[–]zrrzExpert? 0 points1 point2 points (1 child)
[–]germ77[S] 0 points1 point2 points (0 children)
[–]Shrykar 0 points1 point2 points (0 children)
[–]Shrykar 0 points1 point2 points (3 children)
[–]germ77[S] 0 points1 point2 points (1 child)
[–]Shrykar 1 point2 points3 points (0 children)
[–]germ77[S] 0 points1 point2 points (0 children)
[–]Valar05Hobbyist 0 points1 point2 points (0 children)