
and when I use rigidbody2D.velocity I get an error there is no rigid body attached

and when I use rigidbody2D.velocity I get an error there is no rigid body attached
Rigidbodies can’t be enabled or disabled like other components. You have to add or delete them altogether to get the same effect.
To "disable" a rigidbody you usually set isKinematic to true. However removing it (Destroy) and readding one (AddComponent) is of course also possible.
– Bunny83Setting IsKinematic to true would mean that if the object is moved via transform.translate or similar, other colliders would still be affected by it, no?
– ChernoI think you guys miss the point of the question: "when I use rigidbody2D.velocity I get an error there is no rigid body attached"
– Vitor_rThere’s a difference between Rigidbody and Rigidbody2D, they’re both different things, altho it might seem they are the same. Same as for OnTriggerEnter and OntriggerEnter2D for 2D colliders.
does GetComponent<Rigidbody2D>().velocity work
Are you sure that the script trying to access the rigidbody2D is in the same GameObject as the Rigidbod2 2D component?
– Vitor_r