Enemy snowball Collisions
Blitz3D Forums/Blitz3D Beginners Area/Enemy snowball Collisions
| ||
OK maybe I didn't solve my question :(. I made a new topic because I knew people wouldn't respond to the other one. I have a function that detects a player snowball vs. the enemy. I have copied it and made another function that I have changed to be a enemy snowball vs. player collision but it isn't working. The debug log isn't even registering that the snowball has collided. What else do I need to change to fix this? The Player snowball function: Function esnowball_collisions() For a.snowball = each snowball For collision_id = 2 to CountCollisions(a\mesh) collision_entity = CollisionEntity(a\mesh, collision_id) If GetEntityType(collision_entity) = type_enemy enemyhealth=enemyhealt-a\damage DebugLog "playerhealth" + playerhealth playerhealth=playerhealth-a\damage FreeEntity a\mesh Delete a Exit End If Next Next End Function |
| ||
2 things I noticed- Shouldn't this line: For collision_id = 2 to CountCollisions(a\mesh) ;BE this instead: For collision_id = 1 to CountCollisions(a\mesh) And also: If GetEntityType(collision_entity) = type_enemy ;Shouldn't you check to see if it hit the player... not the enemy? If GetEntityType(collision_entity) = type_player |
| ||
I've changed the things you said, same result. |
| ||
Have you remembered to add the new function into the program loop? I know I've done that before and not realized I never added it into the main loop! |
| ||
Yah I've declared it in the main loop. |
| ||
I'm afraid you'll have to post the code for anyone to help. |
| ||
Here it is: |
| ||
Whenever you wish to use collisions, you have to tell Blitz what collides with what. Above the Main Loop, change this line in your game:Collisions type_playersnowball, type_enemy, 2,2 to these lines: Collisions type_playersnowball, type_enemy, 2,2 Collisions type_enemysnowball, type_player,1,2 ;note the 1,2. 1 means "sphere to sphere" check. It took me a little bit to figure this out, but I got it to work on my end, I just had to replace your media with Blitz primitives. It should work if you add in the extra collisions line, but I did do a lot of debugging, so I might be forgetting something else important I changed. Let me know if it doesn't work. Last edited 2012 |
| ||
Thanks that's great its really coming together now! One final thing then i'll shut up. I have it set up so when you click the right mouse button the enemy shoots a snowball. I know how to make it loop forever but I don't want a huge spray of snowballs. How do I make it so it delays the snowball throwing. If MouseHit(2) Then a.snowball = New snowball a\mesh = CopyEntity(snowball) a\id = 2 a\damage = 5 PositionEntity a\mesh,EntityX(enemy),EntityY(enemy),EntityZ(enemy) RotateEntity a\mesh, EntityPitch(enemy),EntityYaw(enemy),EntityRoll(enemy) EntityType a\mesh,type_enemysnowball End If |
| ||
Are you talking about throwing x amount of snowballs per second? If so, your best bet would be to either use Millisecs() with timers, or use a frame counter as a timer. Using the second method, a way to do this might be: frametimer = 0 While Not KeyDown(1) ThrowSnowballs(frametimer) frametimer = frametimer + 1 Wend Function ThrowSnowballs(timer) If timer Mod 4 = 1 ;this basically says that on every 4th frame, throw a snowball. Change 4 to change the rate a.snowball = New snowball a\mesh = CopyEntity(snowball) a\id = 2 a\damage = 5 PositionEntity a\mesh,EntityX(enemy),EntityY(enemy),EntityZ(enemy) RotateEntity a\mesh, EntityPitch(enemy),EntityYaw(enemy),EntityRoll(enemy) EntityType a\mesh,type_enemysnowball EndIf End Function I'm not sure if I follow your question, so if this isn't what you mean, try to give me a little more detail as to what you mean by delay the throwing. |
| ||
How would you do this with the Millisecs() command |
| ||
Global snowballtimer = Millisecs() While Not KeyDown(1) ThrowSnowballs() Wend Function ThrowSnowballs() If Millisecs() >= snowballtimer + 1000 ;If 1 second has passed... snowballtimer = Millisecs() ;Reset the timer a.snowball = New snowball a\mesh = CopyEntity(snowball) a\id = 2 a\damage = 5 PositionEntity a\mesh,EntityX(enemy),EntityY(enemy),EntityZ(enemy) RotateEntity a\mesh, EntityPitch(enemy),EntityYaw(enemy),EntityRoll(enemy) EntityType a\mesh,type_enemysnowball EndIf End Function Keep in mind that the above example is time specific, not frames per second specific. In other words, if your game rendering changes speeds, you could end up throwing more or less snowballs than what you are intending to do. |
| ||
I'm getting this weird thing where the more damage the enemy deals, the less snowballs it takes to defeat him. Also, thanks Rob for all your help! Last edited 2012 |
| ||
I'm not sure what the problem would be. My guess is that you're using the same snowball damage from both snowball ID's. Check that the s\damage field is correct with what you are intending to do. |