scaling down
Blitz3D Forums/Blitz3D Beginners Area/scaling down
| ||
hi all, i dont know how to explain what i am trying to do so here it is in points: -i have a cube and a sphere -you move the sphere towards the cube -once the cube and the sphere collide the cube gets shorter and the sphere dissapears Everything works well until the cube and sphere collide. When they do, the sphere dissapears but the cube keeps getting shorter even though nothing is colliding with it. I kind of know why this is but i dont know how to change it. Here is the code (in the main loop): If EntityCollided (sphere, type_cube) And health=>2 Then y=y-1 health=health-1 HideEntity sphere EndIf ScaleEntity cube, x, y, z i put health as 10 and y as 10 in the beginning. Does anyone know how i could make it so that when the sphere collides with the cube, the cube gets shorter by 1 and no more, until another sphere collides with it? Thanks alot |
| ||
sorry, i made a mistake..the stuff i wrote above happens when i dont include the part health=>2. When i do include it (the code above) then nothing happens; the cube stays the same. |
| ||
here is the problem:Graphics3D 1280,800 SetBuffer BackBuffer() light=CreateLight() cam=CreateCamera() ;collision types type_sphere=1 type_cube=2 ;the sphere sphere=CreateSphere() PositionEntity sphere, -4,0,20 EntityType sphere, type_sphere ;the cube cube=CreateCube() PositionEntity cube, 2,0,20 EntityType cube, type_cube x=1 y=10 z=1 ;collisions Collisions type_sphere, type_cube, 2,1 Collisions type_cube, type_sphere, 2, 1 ;health health=10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;MAIN LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While Not KeyDown(1) ;moving the sphere If KeyDown(205) Then MoveEntity sphere, 0.1,0,0 If KeyDown(203) Then MoveEntity sphere, -0.1,0,0 ;shortening the cube If EntityCollided (sphere, type_cube) And health=>2 Then y=y-1 health=health-1 HideEntity sphere EndIf ScaleEntity cube, x, y, z UpdateWorld RenderWorld ;diplaying the height of cube and the health Text 20,20,"y:"+y Text 100,20,"health:"+health Flip Wend End and here is what i would like to happen except instead of that happening every time you press the space bar, it happens each time there is a collision with the sphere and the cube.. Graphics3D 1280,800 SetBuffer BackBuffer() light=CreateLight() cam=CreateCamera() type_sphere=1 type_cube=2 sphere=CreateSphere() PositionEntity sphere, -4,0,20 EntityType sphere, type_sphere x=1 y=10 z=1 cube=CreateCube() PositionEntity cube, 2,0,20 EntityType cube, type_cube Collisions type_sphere, type_cube, 2,1 Collisions type_cube, type_sphere, 2, 1 health=10 While Not KeyDown(1) If KeyDown(205) Then MoveEntity sphere, 0.1,0,0 If KeyDown(203) Then MoveEntity sphere, -0.1,0,0 If KeyHit(57) And health=> 2 Then y=y-1 health=health-1 EndIf ScaleEntity cube, x, y, z UpdateWorld RenderWorld Text 20,20,"y:"+y Text 100,20,"health:"+health Flip Wend End does anyone know? |
| ||
The And operator in Blitz3D is actually bitwise. The expression ( health >= 2 ) evaluates to 1 or 0, meaning True or False respectively. The expression EntityCollided (sphere, type_cube) is simply an integer, the sphere's handle. As it happens this is always an even number. So when you combine them with EntityCollided (sphere, type_cube) And health=>2 the result is 0. Thus your collision code is never executed. Change the test to If EntityCollided (sphere, type_cube) <> 0 And health => 2 Then |
| ||
*edit* what floyd said |
| ||
thank you, that stops the cube from getting too small, meaning you can still see it but do you know what i could do to make the cube only get smaller by 1. What is happening now is that, when the sphere and the cube collide, the cube gets smaller from y=10 to y=1. what i am aiming for is when they collide, y=10 goes to y=9. thanks |
| ||
To get that, use a variable to store the collision. Then, use another variable to store the previous state of the collision:oldcoll = coll coll = (EntityCollided (sphere, type_cube) <> 0) Now, you can compare coll to oldcoll, and if they are different you can respond to it, ie: If coll and (not oldcoll) Then .. |
| ||
yeees thank you so much Warner and Floyd. it works perfectly well now!! thanks :D |