Closed Roland09 closed 8 years ago
Yeah, check out the sword example:
It's quite basic. But it works out the magnitude of the collision
Thanks. That gives only the value at the collision. Is there a way to detect the speed / force while it's being moved? Like a "whoooooosh" sound while you move tennis racket. Or like when you move a lightsaber slow or fast.
would the velocity magnitude not tell you how fast it's moving? a higher velocity means it's moving quicker, right?
Thank you, I found the problem. I was using an attached child with a rigidbody, that's why velocity.magnitude didn't work. This is how it works now:
float speed = 0;
Vector3 lastPosition = Vector3.zero;
protected override void FixedUpdate()
{
base.FixedUpdate();
speed = (((transform.position - lastPosition).magnitude) / Time.deltaTime);
lastPosition = transform.position;
}
Ah cool. Yeah I guess velocity won't work on an object you're moving with the controller because the object itself has no velocity because it's just tracking the controller. But using the magnitude of the positions would give a close enough approximation :)
Do you need to do it in the FixedUpdate? Would Update be ok?
I know FixedUpdate will be a lot more precise but is the precision worth the performance hit?
I only put it in FixedUpdate because I read so. It's not necessary to have it there. If that's a performance problem, I'll put it into Update, thanks for the hint.
It's just that FixedUpdate is run tonnes of times per frame, meaning your speed calculation is run a load more times, the Update is only run once per frame.
FixedUpdate is really useful when dealing with physics calculations because it's really precise and you get a fewer glitches with collisions, etc.
But I feel for getting an approximate speed, you could get away with using just Update. Unless you need it to be really precise.
Good to know. It's currently just for gaming atmosphere, i. e. playing a sound when the user makes a fast gesture.
On Wed, Jun 8, 2016 at 8:52 AM, StoneFox notifications@github.com wrote:
It's just that FixedUpdate is run tonnes of times per frame, meaning your speed calculation is run a load more times, the Update is only run once per frame.
FixedUpdate is really useful when dealing with physics calculations because it's really precise and you get a fewer glitches with collisions, etc.
But I feel for getting an approximate speed, you could get away with using just Update. Unless you need it to be really precise.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/thestonefox/SteamVR_Unity_Toolkit/issues/149#issuecomment-224504450, or mute the thread https://github.com/notifications/unsubscribe/AKdJ6InPf4FR-LcWVmy0xzFKeKe1nu6lks5qJmaqgaJpZM4IwH_L .
Is there a way to detect the speed / force that a controller is being moved? e. g. for a boxing game, how hard you punch?