- Home /
La domanda ha avuto risposta, è stata accettata la risposta giusta
Grid Movement script correction
I found this Grid Movement script: http://wiki.unity3d.com/index.php/GridMove It works perfectly but there is something I would like to change. When i keep the button to move the player and then I leave it, the player keep moving for some tiles then stops. I want the script more sensible to the keybutton pression, with no delay. I'm new to scripting and I know very few about C#(I used the one written in C#). Can somebody help me?
Answer by Eric5h5 · Aug 06, 2015 at 03:00 AM
Nothing at all to do with the script; change the input settings for the appropriate axes to get rid of the smoothing (gravity/sensitivity), so that the values return to 0 immediately.
I still have problem with this script.
if (is$$anonymous$$oving) {
GetComponent<Animation>().Play("Walking");
}
if (!is$$anonymous$$oving) {
GetComponent<Animation>().Stop("Walking");
}
I added these few strings to play and stop an animation due to the movement. The problem is that every step the player does, the animation start again. I just want the animation to loop while the player is moving and then stops when the player stops.. Also the movement is not fluid as it should be. When the object reaches the end position, there's a little pause that makes everything jerky, like even if I keep the button down, the movement it's not continuous. Least but not last, I used these strings to make the player face the direction is moving:
if (Input.Get$$anonymous$$eyDown("w"))
transform.forward = new Vector3(0, 0, 1);
else if (Input.Get$$anonymous$$eyDown("s"))
transform.forward = new Vector3(0, 0, -1);
else if (Input.Get$$anonymous$$eyDown("a"))
transform.forward = new Vector3(-1, 0, 0);
else if (Input.Get$$anonymous$$eyDown("d"))
transform.forward = new Vector3(1, 0, 0);
But it doesn't work properly 'cause the player turns in different position even if is moving. If I'm moving the player to the top and I push one of the setted keys, the player keep moving top but facing the wrong direction. I don't think this is the best way to do this. How can I fix these problems?
@Burton-kun: To make it move correctly when combining directions, you should have a Vector3 direction, set it to zero at the beggining of your evaluation method (say for instance you do it on Update() as usual) and then sum those values you used to set transform.forward in your script
@Burton-kun: also, you could use
Input.GetAxis("Horizontal") * Vector3.right
ins$$anonymous$$d of checking and setting values manually for $$anonymous$$eyCode.D and $$anonymous$$eyCode.A
Axis named "Vertical" will do the trick for W and S in the way. Since these are Unity'sdefault axis, they also work with the arrows in your keyboard
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Flip over an object (smooth transition) 3 Answers