- Home /
How to add Force on Puck in Air Hockey game
I am making Air hockey game and when i am applying force on to the puck through paddle the paddle move by finger position and puck move are intersecting each other...
I'm not too sure what you are asking here. Could you please clarify your question? Are you developing this for touch screen? I would like to help you, but I can't until i know the exact problem. Also, make sure that both objects have colliders on them and if both of the colliders are mesh mark them as convex.
Actually i am making air Hockey game for ipod and i am facing problem when PUC$$anonymous$$ and Paddle are colliding on that time it is detecting correctly but when i am moving paddle with my finger on that some time puck is co$$anonymous$$g inside the Paddle and i am using $$anonymous$$esh collider and i also mark it as Convex......
Ah. Are you moving the paddle by setting the game object's transform position?
There are issues with physics if you modify the transform ins$$anonymous$$d of applying forces and torque to the object. Switching the rigid body to kinematic = true sometimes solves this.
Also you may need to increase the collision quality on the RigidBody to Continuous, rather than discrete. Also both need RigidBodies attached. And the Paddle needs to be kinematic.
Your problem is common with faster moving objects. There are many ideas about how to address the problem, but not one definitive solution. In addition to the suggestions above, try reducing the Fixed Timestep. From the Edit menu, select Project Settings/Time. Reducing the Timestep increases the number of physics calculations. Another idea is to move an empty game object with your finger and attach the puck to the empty game object using a spring joint. You might also take a look at the Don't Go Through Things script in the Unity Wiki.
Answer by ZenLi · Jul 05, 2013 at 01:00 PM
I have made a similar game and solved the penetration problems...
There are a few things that cause interpenetration:
Make sure your hockey paddles and pucks are the correct scale. The default cube is 1m x 1m x 1m, so scale down the pieces otherwise your forces will be extreme.
Continuous collision only works for cube and sphere and capsule shapes. Mesh colliders won't work, flat cylinder shapes won't work either. So make your puck and paddles colliders out of many smaller shapes, rather than 1 cylinder (e.g. create 6 invisible spheres within your puck mesh, each sphere with a sphere collider)
To interact with the physics world you must use physics functions, so instead of .transform use
.rigidbody.movePosition( new Vector3 ( slideMagnitudeY, 0, -slideMagnitudeX) ) ;
It is best to move an object via a spring joint or mouse joint (create an invisible 'hand' object that moves with the mouse, connect this to the paddle with a joint). That way the physics engine will be able to solve the scene in it's own way, giving you much more accurate results.
Answer by VIPINSIRWANI · Jul 05, 2013 at 10:30 AM
I changed Collision Setting..... and i am setting paddle position with Raycasting from camere like whera i touch via raycast transform position will be set there.. For moving Paddle i am using
else if(touch.phase == TouchPhase.Moved) { LeftFingerMoveBy = touch.position - LeftFingerPos; //dir = (touch.position - LeftFingerPos).normalized; //Direction....
LeftFingerPos = touch.position;
slideMagnitudeX = LeftFingerMoveBy.x / Screen.width;
slideMagnitudeY = LeftFingerMoveBy.y / (Screen.height-200);
}
transform.Translate(slideMagnitudeY,0,-slideMagnitudeX);
Your answer
Follow this Question
Related Questions
Make collision work when animation is playing? c# 0 Answers
collision detection not working? 1 Answer
Collision Problem - Floor Button & Character Controller 1 Answer
Find axis of collision 0 Answers
Fixed Joint Configuration 1 Answer