I am working on a small relaxation prototype for the Vive and I am wondering how I can tackle the following problem. The player is in a rowboat and I want to implement a feature so that the player can move the boat around a bit, using the paddles. But like in real life I only want the boat to move, when the paddle is in the water and also rotate it based on the strength of each paddle. My main question is focused on the forward/backward/side movement. The controller grabbing part is not the problem.
My initial thought is to determine the collision of the paddle with the GO that represents the water.
Im using a shader for my water object, and am thinking of faking the height of the water with a child go that represents a basic collision.
From there, the mechanics of controller grabbing paddle and moving the boat object (with you on it), would be a matter of determining velocity of the paddle in a certain direction.
When I get closer to it, I’ll try to post some samples.
Make an approximation of a paddle planes dynamics in water.
Here’s a very naive sim, but for longish oars it should feel OK.
Assumptions
Oars are fixed in pivots (rowlocks). i.e. oars are correctly rigged in unity with joints, the oar pivoted, its end following inverse locus of VR hand controller.
Water surface is at worldspace 0 Y. Water body is at rest.
Method
All workings below are in worldspace.
Child GameObject to oar end, it’s transform we will call tOar.
Do this per frame:
If tOar.position.y > 0 do nothing.
If tOar.position.y < 0 do this:
Thrust will be in opposite direction to paddle face velocity vector relative to water:
vThrust = K1 * ( tOarPosnLastFrame - tOarPosnThisFrame )
Thrust will be proportional to oar depth beneath water.
vThrust *= K2 * -tOar.position.y
Limit this so full and max mult is when oar is just fully below water.
Thrust will be 1/TAN proportional to incidence of paddle plane through the water, sideways like a knife gives near zero thrust. You could just do linear approx if you want, i.e. 0 … 90 degrees maps to 0.1 … 1.0 thrust mult. You need to find the oars twist, possibly by reading Euler angle Z of rowlock joint.
Constrain thrust to XZ worldspace (zero out Y component). If you have some buoyancy modelled for boat then maybe just scale Y down some and retain a little boat bounce when rowing.
Apply thrust vector to boat rigidbody at oars rowlock position using RigidBody.AddForceAtPosition.
I think you just want COS or SIN, not 1/TAN. So you can just dot product the surface normal of the paddle (either transform.rotationVector3.forward or transformrotation*Vector3.up depending on rest position of oars) and the velocity vector* of the paddle through the water.
*You should also subtract out the relative motion of the boat through the water from the paddle velocity (if you’re moving the paddles at 1 m/s but your boat is already moving 1 m/s through the water, the paddles are actually stationary with respect to the water and should provide 0 thrust.)
Woops, yes in naive sim I mentioned oars ability to push is SIN related to angle of incidence.
Yes a more accurate sim should derive force by scaling the waterspace velocity vector by the incident area of the oar in the water, that is the area of the shadow it would cast if light rays were in direction of oars waterspace velocity. This would allow for all valid boating moves, like if the boat were floating sideways the rower could brake the movement by putting the oar down in the water with its plane parallel to boat side.
Relative motion of boat is already subtracted out using scheme I mention, assuming still water body, it measures worldspace (i.e. waterpsace) velocity of oar end.
Yep, and you can take that scalar and multiply it by the surface normal of the paddle to get the direction of force, so if you twist the paddle 45 deg you get root2/2 of the force and applied diagonally (so you get some up or down force as well)!
And of course you’re right about subtracting out the relative motion of the boat; I haven’t done much VR stuff with moving the player character in a moving vehicle/raft/boat/whatever - I was imagining just tracking the ends of the oar in “living room space”.
Hi @SiliconDroid , I tried this way. Do i need to apply AddForceAtPosition in Update() when its in water? If so, my boat is moving unexpectedly. What are rigidbody properties I need to put to make rotation, position update of boat to be proper. Thanks !!