- Home /
Question by
danijel123 · Aug 17, 2019 at 03:10 PM ·
unity 4.6
RigidBody velocity.magnitude is always zero ?
I have an object for which I want to get velocityMagnitude printed when it collides with another object. On this object I have a rigidBody component, capsule collider and a script. The problem is that it always returns as zero ?
My script:
[using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BagPunchScript : MonoBehaviour
{
public SteamVR_TrackedObject hand;
Rigidbody rBody;
private string punchForce;
private float force;
public Text PunchForceText;
public AudioSource SoundSource;
// Start is called before the first frame update
void Start()
{
rBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rBody.MovePosition(hand.transform.position);
rBody.MoveRotation(hand.transform.rotation);
}
void OnCollisionEnter(Collision other) {
force = (rBody.velocity.magnitude) * 100000;
punchForce = force.ToString();
PunchForceText.text = punchForce;
print("collision");
print(force); // check for velocity.magnitude
}
}][1]
[1]: /storage/temp/144753-unity7.jpg
unity7.jpg
(246.6 kB)
Comment
Answer by Vega4Life · Aug 17, 2019 at 08:09 PM
I believe in order to see any Velocity off a rigidbody when using MovePosition... it either needs to be Kinematic or you should be using FixedUpdate (which you should be doing anyways with what you have).
$$anonymous$$y Rigidbody is Kinematic and I am using FixedUpdate but it is 0 anyways :( I have no idea why...