Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've just been using Unity and chose to learn it by making a Pong game which sounded simple enough as a "hello world" type of game. My goal was to try and encompass enough of the built in engine without needing to write scripts but I ran into a few problems.

Here is my setup so far:

Paddle Game Object:

  • Box Collider
  • RigidBody (Set as Kinematic)

Ball Game Object:

  • Sphere Collider<
  • RigidBody (not kinematic)

Wall Game Object:

  • Box or Plane Collider

I've set my material on my Ball to 'Bouncy' and I get a pretty good bouncing ball (given a starting force).

I've also added the following script to the Paddles:

void OnCollisionEnter(Collision collision)
{
    BallRidigBody.AddForce(rigidbody.velocity);
}

Here are some of my problems:

  1. Collision: I was trying to figure out why my kinematic objects wouldn't collide before stumbling upon the collision matrix. I was wondering what are good approaches to enable kinematic collisions for my setup;
  2. Forces: I'm confused how ApplyForce should be used. Even if I pick ForceMode.Impulse, is that a constant force? I'm a bit stuck on how to get proper bouncing off the walls and paddle. Since I've already applied a starting force, should my wall apply force on an onCollisionEnter method or change the velocity?
share|improve this question
1  
Pong does not impart force based on movement of the paddles, merely directs the ball based on position of the collision relative to the paddle (which is not a realistic effect of a box-shaped paddle). So you should explain what you actually want since "Pong" is not it. –  Warwick Allison Sep 22 '11 at 9:13
add comment

1 Answer

up vote 3 down vote accepted

For problem 1, you can't, as the matrix shows. You have to make them non-kinematic and set their position using forces or rigidbody.MovePosition. Expect very high velocities to result.

For problem 2, you need not apply any forces. Pong uses perfectly elastic collisions, which you can get by settng the PhysicMaterial to be frictionless and have bounciness of 1.0. If you do apply forces for non-Pong reasons, the different modes merely avoid having mass factor into the calculation.

I understand that you're just using Pong as a learning exercise, but it uses such unrealistic physics that you're likely to have to struggle against the physics engine to get anything like Pong.

share|improve this answer
    
thanks. that's what I had found. I thought building something simple would be a good learning excercise but I guess something too simple is difficult with a robust engine, –  Setheron Sep 22 '11 at 15:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.