If i push the W button my char (a cube) uses this script to move forward:
if (Input.GetKey(KeyCode.W))
{
transform.position.z += 0.3;
}
But then it teleports into objects in stead of pushing them.
Does anyone know how to really move it instead of teleporting little bits?
it looks like i dont have colliding at all on the Pic, but i have…
it just goes somethimes in other coins
(the blue bar is the player controlled object)
If you want your objects to collide, you have to give them colliders and rigidbodys. And yes in an digital world every move is an kind of teleporting. Even rigidbodys will check where they intersecting for the simulation. You may use CharacterController if you want to stop at colliders.
You will have to check for collisions and as the objects collide, move your character back or do not move it this frame. If you want it to push the game objects, program it.
Alternatively use the integrated physics system and mark the collider on your character as kinematic. Then you will have control, but it pushes other colliders out of the way.
You will have to tell the objects how they behave, if you do not make sure something happens as you want it, it will not happen.
(Actually there is a lot of stuff unity makes easy, but you have to give life and behaviour to your game objects yourself)
And one little tip:
Frame times can vary so this will give you a constant speed:
if (Input.GetKey(KeyCode.W))
{
transform.position.z += 0.3 * Time.deltaTime;
}
I think you are looking for transform.Translate() to use for smooth movement instead of jumping by a set amount as you are doing now by changing position directly.