im Getting this error
/Users/shubhammayekar/Desktop/lynda game/Assets/scripts/Player.cs(40,40): Error CS1061: Type UnityEngine.Component' does not contain a definition for
velocity’ and no extension method velocity' of type
UnityEngine.Component’ could be found. Are you missing an assembly reference? (CS1061) (Assembly-CSharp)
my code
var absVelX = Mathf.Abs (rigidbody2D.velocity.x);
Maybe you can try setting a variable declaration to your rigidbody2D first, like Rigidbody2D rb; then in start say rb = getcomponent();
after that try var absVe1X = Mathf.Abs (rb.velocity.x);
that should return you the absolute value of the rigidbodies velocity on the X axis.
RigidBody.velocity.magnitude returns a single absolute float for velocity. However, if youre looking for a Vector you would need to use Mathf.Abs for each coordinate.
AbsVelocity = new Vector3(Mathf.Abs(rb.velocity.x), Mathf.Abs(rb.velocity.y), Mathf.Abs(rb.velocity.z))