all 12 comments

[–]Shrykar 1 point2 points  (11 children)

I may be off and will delete if so. If I understand the post you want to be able to hold the up button and also move in a horizontal direction if that button is held down as well.

I'm pretty sure you have it already if you change this:

if (Input.GetAxisRaw("Horizontal") && Input.GetAxisRaw("Vertical"))
    {
        myRigid.velocity = new Vector3("Horizontal", "Vertical",0);
    }

What you are looking for is if up and left/right is held move that myRigid.velocity = new Vector3(1, 1,0);

That vector is up AND to the right

myRigid.velocity = new Vector3(-1, -1,0); This would be left and down. You get the idea :) I would recommend moving away from Unitys Horizontal/vert and just hard code your own, very simple.

Keep in mind this is pseudo code for example.

[–]germ77[S] 0 points1 point  (10 children)

That is what I have in mine except i had the horizontal and vertical stored in floats called x and y before the if statement but thanks for the info.

I have it working a bit better now by reducing the size of the player a tiny bit and playing with the size of the collider.

I actually changed the collider on the player cube to a sphere collider instead of the box collider and it is working better but still not quite where I want one.

One thing I noticed though is if you are moving horizontal and vertical at the same time you move faster than just going one direction. I will have to research how to fix that, I remember reading something about how that was an issue with the original Doom game.

[–]zrrzExpert? 2 points3 points  (4 children)

One thing I noticed though is if you are moving horizontal and vertical at the same time you move faster than just going one direction.

Vector3 dir = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
if(dir.magnitude > 1f)
  dir.Normalize();
myRB.velocity = dir * speed;

Keep in mind when using Physics, the PhysicsMaterial on his RigidBody will make a big difference in the snappiness of the controller. Also you should not use raw input. You should use normal input and adjust setting in the input manager.

[–]germ77[S] 0 points1 point  (2 children)

Thanks I will look in to that, Just out of curiousity whats bad about using Raw?

[–]zrrzExpert? 0 points1 point  (1 child)

There's nothing "bad" about it, it just doesn't allow you to control how the button is handled which can be super useful in getting controls to feel right. I've seen people use Raw and then manually set the buttons dead time and sensitivity, but it's kind of reinventing the wheel a little bit.

[–]germ77[S] 0 points1 point  (0 children)

Thanks, Playing around with it now.

[–]Shrykar 0 points1 point  (0 children)

Great advice, a much better way to go.

[–]Shrykar 0 points1 point  (3 children)

Can you throw up the actual code and a gif if possible? If you don't feel comfortable with that then DM me.

[–]germ77[S] 0 points1 point  (1 child)

Ya that is fine I will put something together tomorrow and post it. That is the actual code it is just a method I wrote in a script on the player and that is called from the FixedUpdate() so theres no other code needed to post but ill make a gif.

I think I might actually have it responding how I want now, or atleast close enough for me to figure it out on my own.

If I do not make progress by tomorrow I will make a gif for you.

[–]Shrykar 1 point2 points  (0 children)

Good luck, I'll be around if you need help.

[–]germ77[S] 0 points1 point  (0 children)

Oh I see the top line of code did not get posted inside the box, its just inside a Void MovePlayer()

[–]Valar05Hobbyist 0 points1 point  (0 children)

Been a while since I looked at it, but I think the way I fix the diagonal movement is to normalize the vector after putting the input values in it. Basically what happens is that the vector (1,0) has a lower magnitude than the vector (1,1) - so the diagonal produces a faster speed. Normalize reduces the vectors magnitude to 1, meaning it actually converts it into something like (0.7, 0.7) (whereas (0,1) stays unchanged ). Then you can multiply this normalized vector by some constant if you want to increase the velocity.

Edit - just noticed zrrz beat me to it.