move mesh

Blitz3D Forums/Blitz3D Beginners Area/move mesh

Rook Zimbabwe(Posted 2004) [#1]
OK how does one pick a path and move mesh on that path.
I am psuedocoding here.

1 posisiotn dice entity off screen
2 use POINTENTITY to point the entity to the gameboard entity
3 use position entity in a loop until dice entity hits gameboard entity
4 show dice entitys true number selected by RAND

IS this how it would work? I have tried that and I have looked at a lot of missle code and other "shooter" code trying to figure out how to animate those small dice entity .X meshes. I don't think I am on the right track.

Opinions wanted!


Neo Genesis10(Posted 2004) [#2]
Two ideas for you, neither of which is completely appealing though.

1) Fix the dice animation so that a particular face always shows up when the animation finishes. Then re-texture the dice depending on the random value.

2) Have 6 animations - one for each possible outcome.


eBusiness(Posted 2004) [#3]
I don't think you need pointentity, it's for rotating an object. Opinion: Maybe this dice stuff is a bit hard for a beginner, no offence.


_PJ_(Posted 2004) [#4]
Theoretically:


I assume you want the dice to be 'thrown' from off-camera to land and bounce on the game board, roll a bit and end up showing the random number.

1 posisiotn dice entity off screen use PositionEntity for this

2 use POINTENTITY to point the entity to the gameboard entity

NO - BECAUSE THE DICE WILL BE CHANGING FACING AS IT ROLLS/SPINS AND BOUNCES. IF YOU KEPT IT POINTED AT THE BOARD, IT WOULD JSUT LOOK LIKE IT MOVES STRAIGHT TOWARDS THE BOARD.
Instead, create a pivot CreatePivot()
PositionEntity the pivot to EntityX,EntityY,EntityZ of the Dice

choose random start facing for dice (This will determine the final value shown)

EntityParent Dice,Pivot

------------------Loop-------------
3 MOVE PIVOT along required path
TurnEntity Dice
------------------Loop-------------

4 When Dice has reached end of path and is stationary, use entitypitch,yaw and roll to determine number shown...

(or similar using TForm commands)

Its true, to show a dice being thrown and read the score shown is quite complicated.

It may be beneficial to 'cheat' and have some pre-calculated standard routines for generating a specific number.

For instance

DiceValue=Rand(1,6)

If DiceValue=1 Then DoDiceRoutine(1)
If DiceValue=1 Then DoDiceRoutine(2)
If DiceValue=1 Then DoDiceRoutine(3)
If DiceValue=1 Then DoDiceRoutine(4)
If DiceValue=1 Then DoDiceRoutine(5)
If DiceValue=1 Then DoDiceRoutine(6)


There are still ways of doing this more efficiently, but the coding gets more techy.....


Rook Zimbabwe(Posted 2004) [#5]
All very good ideas.
eBusiness... not offended... though I am not exactly a beginner in programming... I AM a beginner in B3D.

I just wish there was a way to define a path in B3D and then I could just spin the dice and tell it to follow the path and show whatever random number th computer elected.

But that starts to sound like : "And I want the computer to write the game for me too... oh and add some really cool graphics!"

It is hard, but thats a good way to learn. Solve a hard problem.

I know sometimes my answers don't sound like solid coding advice.

I also know that I approach problem solving differently than most people. Non-Canon as it were.

This is what I am going to play with today. This problem. Any ideas are welcome. I think this is a necessary problem not only for me but what to do with an entity. ANY entity. to make their path look more real.

I am also going to look at the gargoyle example.

I think Malice has a good idea as well. All strong thoughts.

--Rook Z


eBusiness(Posted 2004) [#6]
I'm not shure if you are already confident with this, but when you wan't to make anything with physics, you need in addition to the three position variables three movement variables, if you want the thing to rotate, you will also need three rotation variables, and three for the rotation speed. And don't forget to apply gravity to the vertical movement. The hard thing about the dice is really to know what happens when the dice hits the table, I must confess, I not really shure how to handle that matematically.

I'm sorry about the noob thing.


Rook Zimbabwe(Posted 2004) [#7]
I did it... sort of.

Look at this. I used the code resources in B3D to learn how to create an animation. Then I rotated and moved the entity and created 10 frames for it to go through.

; how to animate and rotate during that animate

Graphics3D 800,600,0,2				; set screen size
SetBuffer BackBuffer()
SeedRnd(MilliSecs()) + Pi

AppTitle "YUTZ - Dice game for the rest of us!","Do you want to exit YUTZ?"


camera=CreateCamera()			; create something to see with
PositionEntity camera,6,6,0
RotateEntity camera,40,55,0

light=CreateLight()				; I will dispense with the biblical reference
RotateEntity light,45,0,0		; move the light a bit to create shadows on the model
AmbientLight 44,44,41	

; Load table
table=LoadMesh("board1.x")		
UpdateNormals table				
EntityFX table,0
RotateEntity table,0,0,0
EntityType table,2
PositionEntity table,-3,-.9,5.25
ScaleEntity table,.015,.015,.015

; Load mesh
die2=LoadMesh("sixdie.x")		
UpdateNormals die2	
EntityPickMode die2,3
EntityType die2,1			
EntityFX die2,0

Collisions 1,2,2,2 ; it has to interact with the board
; 					 too bad I can't figure out a bounce without a lot more code

; Lets animate the dice and "record" the 3D animation for later playback
ypos#=10
xpos#=10
rx#=0
ry#=0
rz#=0
For frame=1 To 10
;Drop the ball from height 10 to 2
ypos = ypos - spd#
xpos=xpos-spd#
spd#=spd#+.27
rx=rx+22
ry=ry+25
rz=rz+99
RotateEntity die2,rx,ry,rz
PositionEntity die2,xpos,ypos,2
rx=rx+1
ry=ry+1
rz=rz+1
RotateEntity die2,rx,ry,rz

SetAnimKey die2,frame
Next

;Now we need to add the frames we've just made to the sequence of "film"!
seq = AddAnimSeq(die2,frame-1) ; total number of frames

;Play it back ping-pong!
Animate die2,3,0.15 ; mode 3 is one time
While Not KeyHit(1)
UpdateWorld
RenderWorld
Flip
Wend
End
--> NOTE <--- hitting {shift} + {esc} clears the topic post box... Hit that instead of !

ANYWAY...

To get the thing to do a gentle curve I think I only have to move it 2 forward and 1 down. A steep curve would be 1 forward and 2 down.

I modified the code from the set of ANIMATE commands in B3D. and modifyed the entity to tumble as it moved... Now to try all 4.

: )

Still making them land and show the right face may take the idea of Malice to do... More thinking needed.

--- Rook


WolRon(Posted 2004) [#8]
This is an idea. Could be bad, could be good.

Start with the dice on the table showing the correct face and then throw it back at the camera (rotating and such) but recording key frames along the way.

Then play that recording in reverse for the user to see.


Rook Zimbabwe(Posted 2004) [#9]
you know Wolron... That isn't bad. It is a backwards approach which I personally think is the best for solving problems! I am gonna try that too!

-rook


Ross C(Posted 2004) [#10]
Rook, if you ever press the escape key again, press Ctrl+Z, directly after it, to undo it. You only get one undo step!


Rook Zimbabwe(Posted 2004) [#11]
Oy! {slapping head} CTRL+Z works here too?!?!!!!