Hello,
I’m working on a Unity SteamVR project and I’m having an issue with velocity. My project is a racquetball game of sorts and I’m trying to create a handler for when the ball hits the racket.
The setup is as follows.
- The ball is a prefab that instantiates 10 seconds after runtime begins.
- The ball and the racket both contain Colliders and RigidBody components that are set to Continuous Dynamic.
- The racket inherits it’s position and rotation from the SteamVR tracked motion controller.
- The racket contains a script component with an OnTriggerEnter method that sets a bool named “rightRacketCollision” to true when it collides with the ball.
- The SteamVR tracked motion controller object contains a script that checks if “rightRacketCollision” is true, and if so, it needs to set the velocity of the ball to the velocity of the tracked motion controllers. It doesn’t

- The SteamVR tracked motion controller also holds a public reference to the ball prefab. I’ve assigned the ball prefab to it’s variable in the editor via drag and drop.
That’s pretty much it, but the Ball velocity does not change when it collides with the racket. As you’ll see in my script (below) I’ve tried using Debug.Log at several junctures and everything checks out (see the screen capture).

Here is my script.
using UnityEngine;
using System.Collections;
using System;
[RequireComponent(typeof(SteamVR_TrackedObject))]
public class SetRightVelocityBall : MonoBehaviour
{
private BoolKeeper _refBoolKeeper;
public GameObject _refBall;
SteamVR_TrackedObject trackedObj;
SteamVR_Controller.Device device;
void Awake ()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Start ()
{
_refBoolKeeper = GameObject.Find("BoolKeeper").GetComponent<BoolKeeper>();
}
void FixedUpdate ()
{
device = SteamVR_Controller.Input((int)trackedObj.index);
if (_refBall)
{
Debug.Log("_refBall is not null");
}
if (_refBoolKeeper.rightRacketCollision == true)
{
bounceBall(_refBall.GetComponent<Rigidbody>());
}
}
void bounceBall (Rigidbody rigidbody)
{
rigidbody.velocity = device.velocity;
rigidbody.angularVelocity = device.angularVelocity;
Debug.Log ("GOT IT!");
}
}
Does anyone have any idea as to why the ball velocity isn’t changing? Many thanks in advance!