Shooter
Blitz3D Forums/Blitz3D Programming/Shooter
| ||
Does somebody know how to shoot? The sight targets the person and you click to fire. |
| ||
Does somebody know how to shoot? Yeah, pull the trigger.I didn't see any code in there for gathering mouse input so you must be looking for this: If MouseDown(1) and Fire = False ;create a bullet (usually copy a bullet entity) ;point it in the camera's direction ;give it a velocity Fire = True FireTime = Millisecs() EndIF If Fire = True If Millisecs() > FireTime + 300 Then Fire = False EndIf I did a simple First Person Shooter code a few months ago. You can find it at my website here. |
| ||
Is there a way to use the sight (a 2d image) and fire it like that? |
| ||
Your last statement didn't make any sense. Try rephrasing it. DESCRIBE the problem. Don't be afraid to type type type type type type type ... |
| ||
He wants to use the sight to aim, ie: fire in the direction the sight is pointing. It was a pretty clear statement Wolron :) Blitz Programmer, you'll have to use the picking commands to do that. Tracer |
| ||
Yeah, although if the target goes beyond vision (ie there is no target) the bullet will flay randomly, so make sure to set up a system for checking that case... |
| ||
fire in the direction the sight is pointing. Ahh, but that's not what HE said. Anyways, the code I showed you will still do that, just aim the bullet at the target behind the crosshairs. As Tracer said, you can use the picking commands (LinePick, EntityPick, etc.). |
| ||
I'm not that good at Blitz3D especially doing picking. How could I do that using LinePick? |
| ||
I changed my code to be like yours but it says 'Varible Type Mismatch.' |
| ||
Yes, but on which line? Take note of which line the cursor is on when you receive that alarm. That will tell you which variable is the culprit. A 'Variable Type Mismatch' is caused by something such as the following: a# = 3 ;later on... a$ = "hello" a$ can't exist because a has already been declared as a float (a#) By the way, I see that you are closing your opened files after the program ends. It's probably best to close them as soon as you are done using them. |
| ||
On this line:bullet.BulletType = New BulletType |
| ||
See, you've already assigned Bullet/bullet as an integer in this statement:Global Bullet = LoadMesh("Weapons\Bullet.3ds")Just use a different variable name. |
| ||
I can't get my bullet-Enemy collision working. I'm trying to get it to delete the enemy and delete the bullet when they collide. |
| ||
Quickly looking through your code, I only see one Collisions commandCollisions 1,2,2,2(so you have collisions set up for entitytypes 1 and 2) But it looks like your EntityTypes for bullets and enemies are 3s and 4s, so you need to set up collisions between them as well. By the way, why don't you go back and edit your previous posts and change them all from [code] commands to [codebox} commands :) |
| ||
I did what you said but it doesn't work. |
| ||
Please, BlitzProgrammer, try to EXPLAIN the problem. Don't just write 'it doesn't work'. Dude, I think you messed up big. I'm not even sure if this is possible: For EnemyType.EnemyType = Each EnemyType For BulletType.BulletType = Each BulletType If EntityCollided(BulletType\mesh,3) = EnemyType\mesh Then FreeEntity EnemyType\mesh FreeEntity BulletType\mesh Delete EnemyType Delete BulletType EndIf Next Next You set the variable names in these loops to equal the names of the variable types. As far as I know, that's not possible (and I'd be surprised if you didn't get compiling error messages). Change the EnemyType and BulletType variable names to something else, for instance like this: For thisEnemy.EnemyType = Each EnemyType For thisBullet.BulletType = Each BulletType If EntityCollided(thisBullet\mesh,4) = thisEnemy\mesh Then FreeEntity thisEnemy\mesh FreeEntity thisBullet\mesh Delete thisEnemy Delete thisBullet EndIf Next NextBy the way, did you notice above that I changed the entitytype from 3 to 4? It appears that you were checking for collisions between thisBullet and all the other bullets... |
| ||
When I shoot the box(enemy), it pops up with an error that says 'Memory Access Violation'. |
| ||
That might be due to the problem I noted above. Did you try making the changes I described? |
| ||
Yes I did. It still does the mem access violation. Sometimes it goes right through the enemy |
| ||
Dude, you did the same thing in this section of code:If MouseDown(1) bulletType.BulletType = New BulletType bulletType\mesh = CopyMesh(bulletMesh) RotateEntity BulletType\mesh,EntityPitch(player,1),EntityYaw(player,1),EntityRoll(player,1) PlaySound GunFire PositionEntity BulletType\Mesh,EntityX(player) - .1,EntityY(player) - .134,EntityZ(player) - .8 EntityType BulletType\Mesh,3 EndIf You already used the variable named BulletType as the name of a TYPE. You can't use it again (even lowercase bulletType) as a type-instance-handle. Change it to this: If MouseDown(1) thisbullet.BulletType = New BulletType thisbullet\mesh = CopyMesh(bulletMesh) RotateEntity thisBullet\mesh,EntityPitch(player,1),EntityYaw(player,1),EntityRoll(player,1) PlaySound GunFire PositionEntity thisBullet\Mesh,EntityX(player) - .1,EntityY(player) - .134,EntityZ(player) - .8 EntityType thisbullet\Mesh,3 EndIf |
| ||
And here you did it again:For bulletType.BulletType = Each BulletType FreeEntity bulletType\mesh Delete bulletType Next For EnemyType.EnemyType = Each EnemyType FreeEntity EnemyType\mesh Delete EnemyType Next Do you see what you're doing wrong in the above two loops? |
| ||
I still have that problem. It still says Mem access violation. In the blitz debugger it says that thisEnemy.EnemyType (Null) The error occurs on this line: If EntityCollided(thisBullet\mesh,3) = thisEnemy\mesh Then |
| ||
Did you even read my posts above??????? You still haven't changed the two loops I mentioned in the post just above your last post. And look at this: For EnemyType.EnemyType = Each EnemyType If LevelType$ = "Terrain" Then PositionEntity EnemyType\mesh,Rand(0,ImageWidth(terrain)),0,Rand(0,ImageHeight(terrain)) ElseIf LevelType$ = "Maplet PositionEntity EnemyType\mesh,Rand(0,MeshWidth(Level)),0,Rand(0,MeshHeight(Level)) EndIf EntityType EnemyType\mesh,4 NextYOU DID THE SAME THING! You can't do this: For EnemyType.EnemyType = Each EnemyTypeEnemyType is a TYPE. You can't use it as a variable. variable type | | | | V V EnemyType.EnemyType Change the variable to something else, like 'thisEnemy'. |
| ||
I didn't see that in my code. |