- Home /
move an object instead of teleporting little bits
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)
in a 3d animation no object ever "truly" moves. they always teleport. You just teleport your objects by small amounts and in short iterations. $$anonymous$$AGIC!
Check out Time.deltaTime :)
don't modify single position attributes directly, wouldn't even be valid if you used C#
it would be better to use a vector direction, a speed and Time.deltatime
Or, the better and ment-for-this way, add a CharacterControllerComponent and use it as discribed at http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.$$anonymous$$ove.html
Answer by Dragonlance · Oct 03, 2012 at 02:42 PM
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;
}
ah thanks a lot, i used a rigidbody with mesh colliders. i also kinda solved it by reducing speed to 0.1 i shall upload a screenshot of what i have
Answer by AyJayKaySoft · Oct 03, 2012 at 02:05 PM
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. http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.html
i already gave them rigid body's and colliders sorry for not telling
Answer by BBG · Oct 03, 2012 at 05:03 PM
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.