Help Wanted

Random Movement: Also fixed movement – buddboy

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
I'm doing a 3D pong remake (I know, its basically cliche, but I need more experience) in Blitz3D. I can't figure out how to do two things: get the other paddle to move randomly, and how to keep both paddles on screen. also I will be needing to get physics to work for the ball later on... any help will be appreciated.

------------------
that post was really cool ^
|
[|=D) <---|| me

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
by the way here is my code so far.


Graphics3D 800,600
SetBuffer BackBuffer()

AmbientLight 255,255,255


;player paddle
Global player = LoadMesh("pongpaddle1.3ds")
player_tex = LoadTexture("pongpaddletex.png")
EntityTexture player,player_tex
TranslateEntity player,8.6,0,0

Global player2 = LoadMesh("pongpaddle1.3ds")
player_tex2 = LoadTexture("pongpaddletex.png")
EntityTexture player2,player_tex2
TranslateEntity player2,-8.6,0,0

;camera
Global camera = CreateCamera()
CameraRange camera,1,100000
CameraFogMode camera,1
CameraFogRange camera,60,200
PositionEntity camera,0,2,-10.5
RotateEntity camera,10,0,0

;main loop
While Not KeyHit(1)

If KeyDown(200) TranslateEntity player,0,0.2,0

If KeyDown(208) TranslateEntity player,0,-0.2,0
UpdateWorld

RenderWorld

Flip

Wend

End

------------------
that post was really cool ^



|
[|=D) <---|| me

[This message has been edited by buddboy (edited November 11, 2006).]

[This message has been edited by buddboy (edited November 11, 2006).]

[This message has been edited by buddboy (edited November 11, 2006).]

[This message has been edited by buddboy (edited November 11, 2006).]

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
Wouldn't you want player2 to move with the ball? Or at least try (so you can at least win against it).

But to make it move random (for which ever reason you wish), you would probably make a varible that determines if the paddle is going to move up or down (maybe like Move_Up=1, move paddle up, if = 0 move paddle down), then use RND and SeedRND to make those numbers that dictate Move_up varible randomize.

------------------

[This message has been edited by LAVA (edited November 11, 2006).]

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
hmm... but how?

i couldn't figure out how to get SeedRnd to work or how to make Rnd work either.

lol im just going to wait until tomorrow when im not exhausted.

yeah i would want it to move with the ball... now i just have to figure out how to get the ball to move without going offscreen...

------------------
that post was really cool ^
|
[|=D) <---|| me

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
Well you could do a number of things to keep on the screen.

A) Position Oriented: If the ball goes past a certain coordinate make it move down or bounce off or whatever.

B) Marker Oriented: If the ball's mesh intersects invisible markers (using entity alpha command) make it move down.

C) Area Oriented: Make a giant invisible cube that encompasses the playing field, and if the ball is not intersecting it, make the ball move down.

------------------

[This message has been edited by LAVA (edited November 11, 2006).]

Realm Master

Member

Posts: 1971
From: USA
Registered: 05-15-2005
*stares blankly at 3d Code*

been... so... long... since... 3d...

(I suck with collisions becaue I don't know about them, and collisions are the whole point of 3d so I havn't done like ANY 3d)

------------------
yeah, im a little crazy
The following Image was created by me:

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
quote:
Originally posted by Realm Master:
*stares blankly at 3d Code*

been... so... long... since... 3d...

(I suck with collisions becaue I don't know about them, and collisions are the whole point of 3d so I havn't done like ANY 3d)


Collisions are fairly easy in Blitz. What did you not understand? Did you see the examples?

------------------

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
yeah collisions are pretty easy. EntityCollided, EntityCollision, and MeshesIntersecting are all pretty easy to use.

good idea Lava. I was thinking about having a cube around the play area. now i just have to make it work... i couldn't figure out how to get the ball to go in the opposite direction... oh duh i just use a variable for up/down.

------------------
that post was really cool ^
|
[|=D) <---|| me

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
quote:
Originally posted by buddboy:
yeah collisions are pretty easy. EntityCollided, EntityCollision, and MeshesIntersecting are all pretty easy to use.


Yes, you can do that, those are really good for general collisions (if you want to do the work ) and you can use them for specific things, like those commands you mentioned helped me a ton with making the boat in my adventure demo move when the character was on it and you used the keys.

What I use for general collisions is the "Collisions" command and "EntityType" command.

Here is an example of this taken from the collisions exmaple with some editing:

method - collision detection method.
1: sphere-to-sphere collisions
2: sphere-to-polygon collisions
3: sphere-to-box collisions

response - what the source entity does when a collision occurs.
1: stop
2: slide1 - full sliding collision
3: slide2 - prevent entities from sliding down slopes

type_character=1
type_scenery=2
method=2
response=1

sphere=CreateSphere( 32 )
EntityType sphere,type_character

block=Createcube()
EntityType box,type_scenery

;Makes sphere-to-polygon collisions ( so method=2), stop (so repsonse =1)
Collisions type_character,type_scenery,method,response

And of course use Updateworld, so that way it updates the collisions.

------------------

[This message has been edited by LAVA (edited November 12, 2006).]

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
Ok, here is a quick simplified version of Buddboy's code. Just a simple setup of the ball bouncing back and forth.


Graphics3D 800,600
SetBuffer BackBuffer()

AmbientLight 255,255,255

;player paddle
Global player = CreateCube()
TranslateEntity player,8.6,0,0
EntityColor player,0,0,255
ScaleEntity player,0.5,2,0.5

Global player2 = CreateCube()
TranslateEntity player2,-8.6,0,0
EntityColor player2,255,0,0
ScaleEntity player2,0.5,2,0.5

Global ball=CreateSphere()

;camera
Global camera = CreateCamera()
PositionEntity camera,0,2,-10.5
RotateEntity camera,10,0,0

Move_ball#=0.1

;main loop
While Not KeyHit(1)

MoveEntity ball,move_ball#,0,0

If KeyDown(200) TranslateEntity player,0,0.2,0

If KeyDown(208) TranslateEntity player,0,-0.2,0

UpdateWorld

RenderWorld

If MeshesIntersect(ball,player) Then
Move_ball#=-0.1
End If

If MeshesIntersect(ball,player2) Then
Move_ball#=0.1
End If

Flip

Wend

End

------------------

[This message has been edited by LAVA (edited November 12, 2006).]

Ereon

Member

Posts: 1018
From: Ohio, United States
Registered: 04-12-2005
As far as the movement goes Buddboy I think the simplest and most straight-forward approach would be to set of the opponent so that if the ball is above the AI paddle then the AI will move the paddle up, and if the ball is below the AI paddle it will move it down. Give the AI a set movement speed so that the paddle will have a predictable speed (you could even ramp up the speed at higher difficulty levels for a simple difficulty increase system). This allows the coding to be simple for you, and makes the game more interesting because the player can fool the AI by bouncing the ball off walls and little details like that.

------------------

How far that little candle throws its beams; So shines a good deed in a naughty world.

Portia The Merchant of Venice

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
hey buddboy, this should work.. or at least give you an idea about how the ball and AI paddle can be updated.. it's in C++ but written in Notepad (a quickie..) so syntax and/or code might be a bit buggy..

It pretty much explains in code what Ereon said.. but a method I used about 2-3 years ago.. most ppl will use a method such as this..

boundaryPos is the right/bottom position of the boundary, presuming that 0,0 is the top left...

also the paddle in this one will slide along the X axis (left being - and right being +)...

you would most likely also what a condition to not move the AI paddle when the ball is right in the middle.. this *should* just be an addition to the "if ((paddleSize.X * aiSkill) > fabs(ballPos.X - paddlePos.X))" statement with just adding "&& (fabs(ballPos.X - paddlePos.X) > paddleSize.x * 0.1)"

// set at init..
Vector3 ballPos, ballVel, boundaryPos;
Vector3 paddlePos;
float paddleSize;

// the speed to which the paddle can move
float paddleSpeed = 1.0f;

// 0.1 is a hard AI, > 0.5 is an easy one
float aiSkill = 0.45f;


///
// on each update, you just need to update the ball position, check it's within the
// bounds and update the AI. You might wish to make this movement time-based, so
// that it will work on all machines at the same speed.
void Update()
{
ballPos += ballVel;

// still might have some issues, but gives you the general idea
if (ballPos.X > boundaryPos.x || ballPos.X < 0)
{
ballVel.X *= -1;
ballPos.X += ballVel.X;
}
if (ballPos.Y > boundaryPos.y || ballPos.Y < 0)
{
ballVel.Y *= -1;
ballPos.Y += ballVel.Y;
}

// basic paddle AI, first check if the ball is out of the paddle 'hitting zone'
if ((paddleSize.Y * aiSkill) > fabs(ballPos.Y - paddlePos.Y))
{
if (paddlePos.Y < ballPos.Y)
{
// paddle is on the left, move paddle to the right
paddlePos.X += paddleSpeed;
}
else
{
// paddle is on the right, move paddle to the left
paddlePos.X -= paddeSpeed;
}
}
}

BTW, 2D/3D... pong is just the same, if not only just a *bit* different, converting between the two shouldn't be an issue..

------------------
www.auran.com

[This message has been edited by dartsman (edited November 14, 2006).]

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Firstly you need to decide where the camera is going to be, so as to prevent having the camera inside the play area. Pong is really more of a 1d game. the y is never used. if you want to make a truly 3d game its going to get really hard, not to mention requiring a mobile camera to catch and see if the ball is above your paddle. You also don't want it to truely be random. If it was truely random it would be jittery. There is a couple methods you could use.

1: Random Intentions (Made that up)
Set up an array with 2 elements. The first is the random value from 1 to 4, the second the length of the value. So basicly you'll also add a variable. Here's some basic psudo code. Not tested, I'm too lazy right now. Its 2d, but gets the method across if you want I'll write some 3d. (Not very experienced in 3d, but understand it)

Graphics 800,600
Seedrnd Millisecs() ;Seedrnd is the command, Millisecs is the degree, in other words its randomness is based upon millisecs/time. Not exactly clear on how it works, but understand enough.

;Play Box will be from 50,50 to 750,550
;Set up starting positions
pad1x = 100
pad1y = 300 ;Middle of play box

pad2x = 700
pad2y = 300 ;Middle of play box

dim PadActions(1) ;Remember computer counts from 0.

lose = false

While not keyhit(1) or Lose = true ;Lose is a just there for feel.

if PadActions(1) =< 0 ;< is just for safety
PadActions(0) = rnd(1,4)
PadActions(1) = 10 ;This is how long the action will be performed.

endif

if PadActions(0) = 1

MoveLeft()

elseif PadActions(0) = 2

MoveUp()

EXT ;Not willing to write the rest of the code down.
Endif

Wend

2: Coordination

Basically an if statement. If ballx > enemyx, move right
If ballx < enemyx, move left ...

But you make the enemy slower than the player to make up for the player's miscalculations.


So do you want to have y, x, and z involved? or just x and z.The ease of the game will increase/decrease with the coordinates involved.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto