A little help please :)

Blitz3D Forums/Blitz3D Programming/A little help please :)

Phodis(Posted 2016) [#1]
Firstly A big hello to everyone I was here a few years ago..briefly, then to my misfortune discovered Gamemaker. I say misfortune as I DID NOT give Blitz3d a fair chance....what a mistake.
WOW from what I have seen already this is such a kickass system that really has a lot of power.

So, I have spent the last 24hrs watching Youtube videos and looking at heaps of code around this site and Jnoodle; and have come up with the code below. I know Ive basically nicked a lot of it already, but it's my one day throwtogether, and I have already learned heaps.

Basically I am ALMOST up to what I had accomplished in Gamemaker within 24hrs and am over the moon with the results. I mean really.. how the hell is this not as well known!!! I feel like a kid in a candy shop.

SO FAR
I have control of a 3d cube on a Heightmap terrain.. threw in a couple of walls and a water plane that really looks pretty cool. A skybox and a simple Enemy that follow me and follows the lay of the land.. but there are a few questions I have if anyone's able to answer I would be greatfull.

I can do various AI behavior in Gamemaker...so things like random walking in a random direction for a random length of time are ok ands I'll work that out for myself.
But I have 2 questions.
Firstly is Enemy line of site to player detection, and how to go about it. It took a little while to work it out in Gamemaker but I did eventually get it. I'll elaborate... Say there is a wall between the player and the Enemy... I need to know how to tell the Enemy there is a wall between himself and the player... thus not attacking until the player is in site. Just a simple way to do it, not Astar stuff.
Secondly, and the hardest I think is how to shoot a bullet from the player in the right direction in 3d space. This would really help.
Currently to introduce myself into this language, I am simply planning to have a third person AI battle, whereby several enemies on each side will attack each other rinse and repeat.
I will post my progress as I go :D
Cheers all.


Phodis(Posted 2016) [#2]
;Sorry I have no idea how to post code so I'll do it raw.

;This is what I have so far...
;if you want to use this you'll need a few Jpegs
;I have no idea how to post them but you could grab a few off google
;the only tricky one is the Heightmap where you must use a sized image
;of 2x2 eg: 64x64 or 256x256 or 512x512
;You'll also need a terrain texture a water texture and a sky1 texture
;all the above I used all the above from http://jnoodle.com/blitz3d




Graphics3D 1024,768
SetBuffer BackBuffer()

camera=CreateCamera()
RotateEntity camera,25,0,0


;Add extra light
light=CreateLight()
AmbientLight 200, 200, 200



;Make Terrain
Global land = LoadTerrain( "terrain_hmap.jpg" )
tex_terrain = LoadTexture( "terrain_tex.jpg" )
ScaleTexture tex_terrain, 10, 10
EntityTexture land, tex_terrain
PositionEntity land,-512, -15, -512
ScaleEntity land, 2, 25, 2


;Create Water and make it 60% transparent
plane1 = CreatePlane()
texture1 = LoadTexture("water.jpg")
;Stretch out the texture a bit so it looks less "checkered"
ScaleTexture texture1, 10, 10
EntityTexture plane1,texture1
EntityAlpha plane1, .6
PositionEntity plane1, 0, -10, 0


;Create sky
sky = CreateSphere()
skytexture = LoadTexture("sky1.jpg")
EntityTexture sky,skytexture
ScaleEntity sky,500,500,500
FlipMesh sky


;Create player
player=CreateCube()
PositionEntity player,-40,0,5
EntityColor player,50,100,255
;player weapon
weapon=CreateCylinder()
PositionEntity weapon,-40,0,7
ScaleEntity weapon,0.5,2,0.5
RotateEntity weapon,90,0,0
EntityColor weapon,50,100,255
EntityParent weapon,player ;parent the weapon to the player


;Create enemy
enemy=CreateCube()
PositionEntity enemy,-40,0,50
EntityColor enemy,255,0,0


;Create enemy weapon
eweapon=CreateCylinder()
PositionEntity eweapon,-40,0,50
ScaleEntity eweapon,0.5,2,0.5
RotateEntity eweapon,90,0,0
EntityColor eweapon,50,100,255
EntityParent eweapon,enemy ;parent the weapon to the enemy



;create 2 walls
wall=CreateCube()
PositionEntity wall,-70,0,30
EntityColor wall,255,0,0
ScaleEntity wall,10,3,.5 ;WIDTH HEIGHT DEPTH

wall2=CreateCube()
PositionEntity wall2,0,0,30
EntityColor wall2,255,0,0
ScaleEntity wall2,10,3,.5 ;WIDTH HEIGHT DEPTH


;Controls

While Not KeyDown(1)

If KeyDown(205) Then TurnEntity player,0,-.5,0
If KeyDown(203) Then TurnEntity player,0,0.5,0
If KeyDown(200) Then MoveEntity player,0,0,0.3
If KeyDown(208) Then MoveEntity player,0,0,-0.3



;Correct Player Terrain height
objx#=EntityX(player) : objz#=EntityZ(player)
PositionEntity player, objx, TerrainY( land,objx,0,objz ), objz

;below line makes the object move forward at the +1 speed at the end of the line
;PositionEntity player, objx, TerrainY( land,objx,0,objz ), objz+1


;Correct enemy terrain height
objx#=EntityX(enemy) : objz#=EntityZ(enemy)
PositionEntity enemy, objx, TerrainY( land,objx,0,objz ), objz


;reposition camera behind player
PositionEntity camera,EntityX(player),EntityY(player),EntityZ(player)
MoveEntity camera,0,0,-15

;enemy chase player if less than so many units
If EntityDistance( enemy, player ) < 40
PointEntity enemy, player
MoveEntity enemy, 0, 0, Rnd( .1, .19 )
EndIf

;enemy move random
MoveEntity enemy, 0, 0, Rnd(.05,.1)



RenderWorld

Text 10,10, "X: " + EntityX(player)
Text 10,20, "Y: " + EntityY(player)
Text 10,30, "Z: " + EntityZ(player)

UpdateWorld
Flip
Wend
End


RemiD(Posted 2016) [#3]
Hello,


how to tell the Enemy there is a wall between himself and the player


there are several ways to do this :
-one way is to use a combination of deltayaw ( to determine if the character is oriented toward enough the target) and linepick (a kind of 3d line) and pickables (low details meshes), between the eyes 3dpoint of the character and one or several 3dpoints on the target (for example a 3dpoint at the center of the target), and check if the line can reach the target or if it is blocked by an obstacle
some examples here :
http://www.blitzbasic.com/codearcs/codearcs.php?code=923
http://www.blitzbasic.com/codearcs/codearcs.php?code=532

-another way is to hide all lights, to set the ambientlight to the maximum, to color each entity in a specific color and to capture a small render from the character eyes (for example 102x76 pixels for a 1024x768 resolution), then to analyze the colors of the pixels of this small render and to check if the color of the target is found or not. (if the target is behind an obstacle, there will be no color of the target in the small render)
an example here :
http://www.blitzbasic.com/Community/posts.php?topic=103889



how to shoot a bullet from the player in the right direction in 3d space.


-one way is to use positionentity and rotataeentity to position rotate your bullet with the same position orientation than your gun and then move it using moveentity
http://www.blitzbasic.com/b3ddocs/command.php?name=PositionEntity
http://www.blitzbasic.com/b3ddocs/command.php?name=RotateEntity
http://www.blitzbasic.com/b3ddocs/command.php?name=MoveEntity

-another way is to use a combination of tformvector (to determine the properties of a 3dvector depending on an entity orientation/position and the direction you want), and translateentity to move the bullet with the vector properties
http://www.blitzbasic.com/b3ddocs/command.php?name=TFormVector
http://www.blitzbasic.com/b3ddocs/command.php?name=TranslateEntity


good luck!


Dan(Posted 2016) [#4]

;Sorry I have no idea how to post code so I'll do it raw.


When you write a post in this forum, there, above its box is a link: Post reply to topic: (forum codes)


Midimaster(Posted 2016) [#5]
to your second question:
Your code is already very closed to fire a bullet towards the player.

You already know how to turn the enemy towards the player with "PointEntity()". If you now create a new bullet entity with "CreateCube()" as a child of the enemy, then cut the relationship, then move the Cube in z direction only, it will fly directly towards the player.

While Not KeyDown(1)
....
     If KeyHit(57)  ; SPACE key
          PointEntity Enemy, Player
          Bullet=CreateCube(Enemy)
          ScaleEntity Bullet, 0.1, 0.1, 0.1
          EntityParent Bullet,0
     Endif
     If Bullet 
          MoveEntity Bullet 0, 0, 0.1
     Endif
     RenderWorld
.....
Wend



Phodis(Posted 2016) [#6]
Wow!!!! this is awesome stuff there guys... it sucks I have to go to work now, but I'll be right into this when I get back. Damnit I want to call in sick :P

I'll let you know my progress ASAP

Cheers All :D


jfk EO-11110(Posted 2016) [#7]
Also master Linepicks, to test if the enemy can see the player. but the surroundings must be pickable too. Considering the speed of real bullets of like 400m/s, you may directly use Linepick for the shot, show muzzleflash, but no bullet at all. Snipers may need a realistic delay, like 2-3 secs tho. Of course, superpower plasma projectiles are an entirely diffrent story.

Generally, learn about sin, cos and atan2. Atan2 gives you the angle between two points. then use x=x+sin(angle):z=z-cos(angle) to move point A towards point B. This works in any language.