# How can I convert a rigidbody velocity value to some normal reading speed value?

void Update()
{
var vel = rigidbody.velocity;
movementSpeedUiText.text = vel.ToString();


The result is :

what I understand from this ? what is the speed ? I don't want to know only if the player is moving or not but what is the speed. what I see is some vector3.

This is the complete script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerSpeedDistanceController : MonoBehaviour
{
public GameObject target;
public GameObject speedArea;
public float speed;
public Animator animator;
public Text movementSpeedUiText;
public Text distanceFormTargetUiText;
public Text playerDirectionUiText;

private float distance;
private Rigidbody rigidbody;
private Vector3 lastPosition;
private bool isMoving;

// Start is called before the first frame update
void Start()
{
lastPosition = transform.position;
isMoving = false;

rigidbody = GetComponent<Rigidbody>();

movementSpeedUiText.text = animator.GetFloat("Forward").ToString();
distanceFormTargetUiText.text = Vector3.Distance(transform.position, target.transform.position).ToString();
playerDirectionUiText.text = transform.forward.ToString();
}

// Update is called once per frame
void Update()
{
if (isMoving == false)
{
movementSpeedUiText.text = "0";
}
else
{
movementSpeedUiText.text = animator.GetFloat("Forward").ToString();
}
distanceFormTargetUiText.text = Vector3.Distance(transform.position, target.transform.position).ToString();
playerDirectionUiText.text = transform.forward.ToString();

if (transform.position != lastPosition)
isMoving = true;
else
isMoving = false;

lastPosition = transform.position;
}
}


because the player have animator and also some more animators on the childs the movement speed is affected by this animators. even if the player is not moving he is still looks like moving when calculating the speed.

"Forward" is parameter of the HumanoidWalk speed so when I press the W key and the player is moving it's showing the value of the "Forward" parameter.

and because when the player is not moving I don't press on W or any other key it's showing in the movementSpeedUiText text some E long number. That's why I added the part that detect if the player is moving or not and if not I assign "0" to the text.

The problem now is when I press on the W key and move the player the text is stuttering flickering.

• A velocity in Unity is units per second. So this depends on what you think your distance unit is. Mar 22 at 22:55
• ...and of course, the speed is the length of the velocity vector. Mar 22 at 23:01
• @Vaillancourt Edited my question what I tried to do. Mar 22 at 23:14

velocity.magnitude.ToString("F1");