public class MoveObject : MonoBehaviour
{
public float force = 10f;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.forward * force);
}
}
}
void FixedUpdate()
{
rb.velocity = Vector3.ClampMagnitude(rb.velocity, 10f);
}
void OnCollisionEnter(Collision collision)
{
Debug.Log("Столкнулся с " + collision.gameObject.name);
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("Игрок попал в зону!");
}
}