GridMove not working


I copy/past Gridmove’s script on a cube in a simple scene (a plane floor, a cam and a light), and launching it, nothing is happening (when pressing the wasd or arrow keys). Did i miss something making this not as trivial as this simple copy and past to make it work?

thx a lot.

I found why, wanted to share the answer for beginner like me :).

It was actually because of the “run speed” button not being set up.
for now, I // the line

moveSpeed = Input.GetButton("Run")? runSpeed : walkSpeed;

and replaced it with

moveSpeed = walkSpeed;

i’ll learn how to set up this run key later I guess.
but with this, my cube worked perfectly and is moving on a grid.

My new problem now, is collisions, and to not allow my cube “character” to move into a wall if there is one. I activated the box colliders on it, and a rigid body on a wall (a simple cube right now), but they don’t detect each others :).

I’m working with the GridMove script, too, and have been trying to adapt it to a project I’m working on. It uses transform.Translate, which anytime you use transform is basically like teleportation. If you have a rigidbody attached to the gameobject, try something like…

rigidbody.MovePosition(rigidbody.position + speed * Time.deltaTime);

for continually moving characters, and for other things getting controlled by the character but by force, like a car gaining speed as the accelerator is held down, you could use…

rigidbody.AddForce (0, 10, 0);

Also, look at your collision detection in rigidbody is set to Continuous instead of Discrete. Discrete will interact with other rigidbodies (as far as I understand) but Continuous will also interact with other mesh colliders. Continuous Dynamic is overkill and Unity only recommends using it for fast moving objects that need constant collision detection.