Newbie but hooked on Unity - Help with colliders

Hi!

Im a noob with Unity and over all in making games.
Iv got years of experince in programing. ( php, mysql etc.)

I want to make a simple game, like pong!

Iv got the layout of the game, iv got the paddels, iv got the ball. - But here is where it get tricky.

Iv tryid with rigidbodys, boxcolliders and other stuff, but i cant seem to get the paddels to stay inside the arena with out tilting or flying of the screen…!

Here’s the script for movement of the paddel.

var speed = 50.0;
function Update () {

var translation = Input.GetAxis ("Mouse Y") * speed;
translation *= Time.deltaTime;
transform.Translate (0, 0, translation);

}

A working example is found here, to se the effects of the script.

http://www.fuldskrue.dk/pong/pong.html

How do i get the paddel to stay inside the arena?

When trying to fix the transform.position.z = 0, the thing crashes trough the barriers if i put enough force on it.

Is it posible to make it move only inside a given area? fx. z= -5 to 5 ?

I hope somebody can help

//Dennis

You should be able to manually check your position and limit it to the area you wish.

If (transform.position.z > 5) transform.position.z = 5;

And check out the Mathf functions, as Min, Max, and Clamp work well for this sort of thing:

Or you could set up invisible colliders and just keep the paddles in bounds that way.

if your paddles are rigid bodies then use configurable joints to lock the motions of these objects and increase the mass so they are heavy and adjust acordingly so the ball won’t move the paddles and they can move.

Wicked nice…!

So simple, but so effective… - Iv tryed something similar but the < > clamps didnt work for me, and Unity keept throwing errors, so gave up. - But thanks to you guys, im back on track! :smile: