This is my MoveScript:
voidUpdate () {
transform.Translate(speed * Time.deltaTime, 0f, 0f);
}
When it’s on, the player falls through the floor but when it’s off everything is OK.
This is my MoveScript:
voidUpdate () {
transform.Translate(speed * Time.deltaTime, 0f, 0f);
}
When it’s on, the player falls through the floor but when it’s off everything is OK.
transform.Translate will move exactly where it’s told, ignoring collisions. Maybe you want MovePosition instead?
That works but I’d like the object to be affected by gravity (particularly for jumps).
try rigidbody2d.velocity, something like:
float move;
public float speed;
void FixedUpdate ()
{
move = Input.GetAxis ("Horizontal");
rigidbody2d.velocity = new Vector2 (move*speed, rigidbody2d.velocity.y);
}
If you want the object to be controlled by forces, then you need to move it by forces, rather than by setting position updates. Use good ol’ AddForce.