Hit ball with racket
Hi,
I'm developping a VR game with HTC Vive, and i'm starting by making a ball interact with a racket. The ball is a Sphere (radius 0.1) with a rigidbody. The Racket is a cube, in a rectangular shape : x:0.2 y:0.2 z:0.03
The ball interact with the racket quite well at slow speed, but when I move my racket faster, it goes through..
I tried to tweek some physics value : Fixed Timestep to 0.01 (1/90 for the Vive) Solver Iteration : from 6 to a lot a values, even 100 (just for test purpose), it helps a little but not too much.
I also tried to add the DontGoThroughThings scripts but it does not help
I changed the collision detection to "Continious Dynamic" for both and try changing Interpolate to the interpolate and extrapolate..
Nothing will do, How should I achieve this? I do not want to code that (should I?), because it has to feel very realistic (VR..) when my ball is on my racket. I assume Unity should be able to handle that?
Thank you
To move and rotate the ball and rocket use rigidbody methods only ins$$anonymous$$d changing transform. $$anonymous$$eep collision detection to "Continuous Dynamic" and Interpolate to "Interpolate" That should solve your problem
Hi Brijs,
Thank you for your answer. I do not used transform or anything, because it is Virtual reality, I use the S$$anonymous$$mVR plugin and attach a racket to my Touch Controller. It follows the movement of my hand. The ball has a rigid body and react to my racket movement, it works well at low speed but when I speed up, it goes through. I took a look to newtonVr http://www.vrinflux.com/newtonvr-a-free-physics-based-interaction-system-for-unity-and-the-htc-vive/ and it seems running quite smooth, I'll try it. But it's a "black box" solution, I would be happy to know how to handle this issue by myself.
Another article I just found, where they adress my issue of balls going through racket ! http://www.vrinflux.com/newton-vr-physics-based-interaction-on-the-vive/
Brijs is right. As you said "I use the S$$anonymous$$mVR plugin and attach a racket to my Touch Controller", this might be the cause for your problems. Depending on the plugin, there's a good chance, that the Touch Controller is not moved in the physics time step. Whatever is attached to it will fail using any good collision.
Either look for a setting in the plugin that lets the controller change it's Unity internal positions in the physics update loop, OR, which I think is more the case, make the racket FOLLOW the controller by using $$anonymous$$ovePosition and $$anonymous$$oveRotation. It might even be worth to do this with the colliders only and keep the visuals updated the way you do. A question of tuning I guess.
Newton VR does not help in my case. I'll will try to code something like that : I detect contact on my racket (with raycast), and I'll apply a opposite force on the ball based or my current racket velocity, don't know if it will feel realistic ..
I can't do that actually :(, as it changes the transform of the object held, but does not apply force.. I'll will tweak NewtonVR to make it more responsive to fast movement if I can..
Did you ever figure this out? I'm having the same problem. I'm using stonefox's VRT$$anonymous$$ scripts which are similar to newton.
Videos of what my golf game looks like with this frustration:
Unfortunately not.. I'm not sure there is an "on the go" solution with the unity physics.. For now, I change my $$anonymous$$d and started a new game with no high velocity physics needed, that's a shame :(.
Answer by BostonLeeK · Aug 06, 2018 at 11:45 AM
The post is old but If somebody will stuck on this: The only one way to make it working nice is to make collision detection and changing velocity of the ball without rigidbody on the racket.
So, how i made it:
1) create empty prefab (name it RacketController for example) and give him box collider with a trigger and rigidbody with cinematic, like a child of this object i add Racket with only box collider. (I need parent cose i must to change the child visible or not for type of controller tracker or joystick)
2) Add a script to RacketController that change Rigidbody position (important that it is rigidbody) to position of my right controller
3) Add checking velocity of the rigidbody and saving it to variable
4) Create a ball with a rigidbody and sphere collider
5) Create a script and add it to the ball where i cheeking the collision and use such formula
direction = Vector3.Reflect(lastFrameVelocity.normalized, collision.contacts[0].normal);
this.GetComponent<Rigidbody>().velocity = direction * speed;
where lastFrameVelocity is the velocity of the ball on starting collision and collision is the object that ball is touching. And after i just add new velocity to the object. And i the object name is Racket for example i get the velocity from RacketController and multiply it with the ball velocity.
float addForce = RacketController.GetComponent<TrackerFollow>().RacketVelocity.magnitude;
speed += addForce;
And i remove physics material from the ball to make all work done by script.
The final result not best but now the ball not crossing the object through. There need some working with a script to make force on ball more realistic but it work.
Hope for someone this post will be useful. And this is result on video: https://youtu.be/F2_PllPlV4M
Answer by vkapoor · Jan 23 at 01:33 PM
The video link does not work anymore. Can you please post again? I am wondering how you check the velocity of a Kinematic Rigidbody in step 3 above. Do you calculate it based on transform.position?
Your answer
Follow this Question
Related Questions
Racquet in VR, doesnt hit the ball, and sometimes it "sticks" to the ball. 1 Answer
Ball passes through the floor on movement 1 Answer
How to predict where the soccer ball should be intercepted by an AI player after being kicked? 0 Answers
SteamVR Throw/fling object with another object 0 Answers
BallShooting Game Issue with Detecting ball stopping when rolling uphill 1 Answer