Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/115046541324058626
edited title
Link
Tetrad
  • 30.1k
  • 12
  • 95
  • 143

A few questions regarding How can I set up a Pong-style game using the physics/forces system in Unity3DUnity?

changed title, formatting and minor spelling changes
Source Link
bummzack
  • 22.6k
  • 5
  • 63
  • 87

Unity 3: Few General Questions A few questions regarding force and collisionphysics/forces in Unity3D

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 neededneeding to write scripts but I ran into a few snafoosproblems.

So far hereHere is my setup so far:

PaddlePaddle Game Object:
-Box Collider
-RigidBody (Set as Kinematic)

Ball

  • Box Collider
  • RigidBody (Set as Kinematic)

Ball Game Object:
-Sphere Collider
-RigidBody (not kinematic)

Wall

  • Sphere Collider<
  • RigidBody (not kinematic)

Wall Game Object:
-Box or Plane Collider

I've

  • 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 snafoosproblems:

  1. CollisionCollision: I was stuck for a while trying to figure out why my Kinematickinematic objects wouldn't collide before stumbling upon the collision matrix. I was wondering what are good approaches to enable Kinematickinematic collisions for my setup;
  2. ForceForces: I'm confused how ApplyForce is doneApplyForce should be used. Even if I pick ForceMode.ImpulseForceMode.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"onCollisionEnter method or change the velocity?

Thanks!

Unity 3: Few General Questions regarding force and collision

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 needed to write scripts but I ran into a few snafoos.

So far here is my setup:

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 snafoos:

  1. Collision I was stuck for a while 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. Force I'm confused how ApplyForce is done. 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?

Thanks!

A few questions regarding physics/forces in Unity3D

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?
Source Link
Setheron
  • 596
  • 6
  • 16

Unity 3: Few General Questions regarding force and collision

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 needed to write scripts but I ran into a few snafoos.

So far here is my setup:

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 snafoos:

  1. Collision I was stuck for a while 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. Force I'm confused how ApplyForce is done. 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?

Thanks!