I am trying to be able to pickup and throw objects with the Vive MotionController. Currently I can pickup and “drop” objects. The way it is currently working I turn off the phsyics & collision and parent it to the controller mesh. However when I reverse the process it just drops to the ground and doesn’t care about the momentum I am applying to it by waving the controller. How can I apply that force / throw it the direction I wanted when I release the object?
Here is a couple images of what I have so far:
Okay, it looks like the error is something to do with how I am setting the Velocities. Apparently, if I use the MotionControllers themselves or the StaticMeshes attached to them it still comes back X0.0, Y0.0, Z0.0 in both.
My only problem with doing that is that I want the StaticMesh to stay where it is initially set up in relation to its parent object. When I check on the Simulate Physics option it just stays on the ground when I pickup the VIVE MotionController.
Are there settings that will allow me to still accomplish that?
Thanks for your information and patience. I am getting close to getting this working.
In cases where I only want velocity and not the rest of the physical properties, I’ll fake it a bit by caching the position of the object at each frame as “Last Location”. On Tick, query location, compare with last location to get magnitude and vector direction, save location as “Last Location” so it can be calculated upon the next frame.
Obviously this doesn’t scale to a ton of objects, but when you’ve got important aspects of your game, this is a place that you might spend your calculation budget.
Thanks! That worked really well. I can see how it would be a bit intensive on calculations but since I only really need it for the left and right hand it should work just fine. I now can pickup and throw objects just fine.
One other quick thing. This only gets me the linear velocity. Not sure how to get the angular velocity. I am trying to mess with the rotation amounts but not sure what the combination is. Can you help me with that as well?
GetPhysicsLinearVelocity() and GetPhysicsAngularVelocity() for MotionController Components return ZeroVector, but i just found out this functions work for collision sphere (or any other actor component) attached to MotionController.
I also capture the motion controller positions and calculate a velocity vector from that.
Here’s something you’ll want to watch out for: If you’re only capturing the MC position at the current frame and comparing it against the position at the last frame, you’re going to get some pretty wild results if there is even a slight bit of jitter in the hand movement between Frame 0 and Frame T-1. You’ll want to apply some smoothing over time to account for this.
Here’s how I do it:
I create a queue with a fixed length of 10. Every frame, I enqueue the current position of the motion controller. If the queue is full, the last item is dequeued. So, here’s what my data structure looks like:
When the player releases the grip on the motion controller, I then take the current vector values from the priority queue and then I multiply them by a weighting value, then calculate the deltas and sum them together. The most recent hand position should have the most weight and influence over the trajectory, and the oldest positions should have the least weight. The result is a weighted average vector which gives a smoothed value for velocity. So, if the players hand twitches a tad or they do some really rapid movement, we can still get a nice velocity vector and throw the held object in the hand velocity vector.
If the queue has only one position vector, then we can’t possibly create a delta to find velocity, so we just apply a zero velocity. This can happen if the player taps the grab and throw button extremely quickly. It’s rare, but if you don’t handle it, you’ll crash.