January 16, 2021, 09:48:41 PM

Author Topic: Really need help with my sad attempt here.  (Read 5440 times)

Offline phodiS

  • Jr. Member
  • **
  • Posts: 52
Really need help with my sad attempt here.
« on: July 16, 2018, 11:01:27 PM »
     I suck at this I admit it.. I have spend way to long trying to come up with a solution for how to shoot in a 3d world. Truly have tried all over youtube and looking at all I can get my hands on but this really eludes me, Could someone ~please~ take a look at my code here (you can see I tried) and help me with how to shoot straight ahead as my bullets only want to go to one place, and I cannot work out why.  :'(
 
    So far, I have a player ship... moveable with the WASD (I can tweak this part later)
I have an enemy (ground based).. he shoots at the player ship fine (It works but I think the approach is totally wrong)… and the enemy moves around on the ground...once again it works... LOL I know you guys are gunna laugh at the way I did this, but. well anyway any help would be appreciated.
Cheers all.


Graphics3D 1024,768:SetBuffer BackBuffer():camera = CreateCamera():light = CreateLight()

AppTitle "Tiny Galaxy"

;Player
player=CreateCube():ScaleEntity player,.5,.2,1:PositionEntity player,0,0,5
tail=CreateCube():ScaleEntity tail,.1,.2,.2:PositionEntity tail,0,.4,4.2
EntityParent tail,player
st=0;player shoot timer
pfired=0:prange=0:pst=0 pshoot=0
;angle of player turn
wy=.5:sy=.5:ax=.5:dx=.5
EntityParent camera,player
;ENEMY
ex=-10
ey=-10
ez=15
enemy=CreateCube():ScaleEntity enemy,.5,.5,.5:PositionEntity enemy,ex,ey,ez
EntityColor enemy,255,120,120
;EMARKER
emarker=CreateCube():ScaleEntity emarker,1,1,1:PositionEntity emarker,200,0,200
;missile
ebullet=CreateCube()
ScaleEntity ebullet,.1,.1,.5
EntityColor ebullet,255,0,0
PositionEntity ebullet,ex,ey,ez
shoot=0:efired=0:ereload=0

;GROUND
ground=CreateTerrain(512)
PositionEntity ground,-200,-10,0
gtex=LoadTexture("grass.bmp")
EntityTexture ground,gtex

t=0;Enemy bullet timer

; >>>>>>>>>>>>>>>>>>>>    BEGIN LOOP     <<<<<<<<<<<<<<<<<<
While Not KeyDown(1)
; PLAYER CONTROLS
; PITCH ...UP and DOWN
If KeyDown(17) Then pitch# = pitch# - wy+.5 ;W
If KeyDown(31) Then pitch# = pitch# + sy-.5 ;S
; YAW ...LEFT RIGHT
If KeyDown(30) Then yaw#=yaw#+ax+.5 ;A
If KeyDown(32) Then yaw#=yaw#-dx-.5 ;D
; ROLL...TILT LEFT RIGHT
If KeyDown(16) Then roll#=roll#+.2 ;Q
If KeyDown(18) Then roll#=roll#-.2 ;E

MoveEntity player,0,0,.02
RotateEntity player,pitch#,yaw#,roll#

;ENEMY MOVEMENT
emt=emt+1
If emt>800+Rnd(800)
FreeEntity emarker
emx=Rnd(-100,100):emz=Rnd(-100,100)
emarker=CreateCube ()
ScaleEntity emarker,.2,10,.2
PositionEntity emarker,emx,-10,emz
emt=0
EndIf
PointEntity enemy,emarker
MoveEntity enemy,0,0,.01

;ENEMY FIRE CONTROL
If efired=0 PointEntity ebullet,player
t=t+1:If t>5 shoot=1
If EntityDistance (ebullet,player)<20 And shoot=1:efired=1:EndIf
;MOVE EBULLET
If efired=1 MoveEntity ebullet,0,0,.05:erange=erange+1
;ENEMY EBULLET RANGE AND RESET
If erange>500 efired=0:t=0:shoot=0:FreeEntity ebullet
;MAKE NEW BULLET
If erange>500
ebullet=CreateCube()
ScaleEntity ebullet,.05,.05,.3
EntityColor ebullet,255,0,0
ex=EntityX(enemy):ey=EntityY(enemy):ez=EntityZ(enemy)
PositionEntity ebullet,ex,ey,ez
erange=0
EndIf

;PLAYER SHOOTING
x=EntityX(player):y=EntityY(player):z=EntityZ(player)
target=CreateCube()
PositionEntity target,x,y,z+100
pst=pst+1
If pst>10 pshoot=1 pst=0 Else pshoot=0

If KeyDown(57) And pshoot=1
bullet=CreateCube()
ScaleEntity bullet,.1,.1,.02
EntityColor bullet,255,0,250
PositionEntity bullet,x,y,z
pfired=1
EndIf

;MOVE EBULLET
If pfired=1 PointEntity bullet,target MoveEntity bullet,0,0,.5:prange=prange+1
;EBULLET RANGE AND RESET
If prange>400 pfired=0 prange=0 FreeEntity bullet
 

RenderWorld
Flip
Wend

Offline GW

  • Full Member
  • ***
  • Posts: 202
Re: Really need help with my sad attempt here.
« Reply #1 on: July 17, 2018, 12:20:51 AM »
Have you tried looking at all the examples that come with b3d?  The're are many have shooting in 3d space.

Offline phodiS

  • Jr. Member
  • **
  • Posts: 52
Re: Really need help with my sad attempt here.
« Reply #2 on: July 17, 2018, 01:28:21 AM »
   Hi there, yes I had a look at the examples. The closest thing I can see that does what I want to do is an asteroids clone. But how on earth I would translate the shoot code into my base level game here is beyond me.
  The below are the fundamentals of the things I feel I need to know how to do to start making the game I want to. I understand 95% of it, to get by.

Collisions...              Yes understood
Randomization         Yes understood
Imposting models     Yes undewrstood
Texturing                 Yes understood
Movement in 3d       Good enough for now and I can understand what I hjave typed in in the example I posted.
Distance to objects   Yes, easy love it in Blitz3d
for/next/loops          Yes all good.
AI                            I can bumble through it ok.  I have spent a few years in Gamemaker studio GML and have
                               brought a few things there to what I try to program here, and it has helped a lot.
COS/SIN/TAN           Don't need it just yet, but have enough examples I can work with for some AI patterns.
Types                      I think I can use this somehow in the shooting area, but for now I mainly use for collisions.
fields                       Not understood yet.

BUT
Shooting and Repeated shooting   <<< I have not yet found an example I can actually understand.
                                                          What I am trying to do is have models shoot at each other, as you can see I
                                                         managed a dodgey version in the above example, they enemy however
                                                         only fires one bullet at a time... great but limited. I also need to know how
                                                         the player can fire so the fired bullets don't stop everytime the fire button is re-pressed. And aim where the ships facing.
      I can't tell you guys how many hours I have tried to work it out. I have made 3 fair sized games now... one I really like where I have a few animated
zombies walking around in 3d, and as soon as I manage to find out how the devil I can shoot at the bastar@$ I will be able to move on to bigger and
better projects.  I didn't come here on a whim, I have put a lot of time into this and would appreciate if anyone has SIMPLE code or knows of an easy example I could follow
 as it's driving me bonkers here.

Cheers all.

Offline peteswansen

  • Jr. Member
  • **
  • Posts: 58
Re: Really need help with my sad attempt here.
« Reply #3 on: July 17, 2018, 06:46:03 AM »
well this is kinda interesting.... so I see the reddish cube on the ground firing at the plane---  moved plane with WASD for pitch and turn.   It looks to me like the white blocks are created in the distance based on the flight path of the airplane...this is weird.

The airplane only shoots white cube bullets from one side (possible positive z from the airplane center point)- regardless of which way the plane is facing.  So first off there needs to be code to make the bullets shoot from the planes current facing (yaw and pitch).




 

Offline phodiS

  • Jr. Member
  • **
  • Posts: 52
Re: Really need help with my sad attempt here.
« Reply #4 on: July 17, 2018, 06:56:14 AM »
Hi there,
             The blocks are just a couple of cubes joined together as a 3d model... that just has the camera fixed on them. I know its not much at the moment but it's all placeholding until I can get this shooting thing worked out before I go to much further.
             I have some reasonable ideas if I can just get over this hurdle.  :)

Offline peteswansen

  • Jr. Member
  • **
  • Posts: 58
Re: Really need help with my sad attempt here.
« Reply #5 on: July 17, 2018, 07:37:07 AM »
ok I know that..  so you need to pick the lead cube of the plane thing and have the bullets fly from the lead cubes current x,y,z location and have the bullet vector align with the plane current yaw,pitch, and roll...

the pic I added shows the strange cube model of the planes flight path

Please be patient and let others in the group read your message.... then we can help you


Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Really need help with my sad attempt here.
« Reply #6 on: July 17, 2018, 11:14:38 AM »
..regarding B3D and FPS shooter framework, you should not look further than this, and probably after having this, any question about current topic should be considered an insult :) ... credits goes to Rob Cummings..




..whole project source/media in attachment..




Offline TomToad

  • Hero Member
  • *****
  • Posts: 521
Re: Really need help with my sad attempt here.
« Reply #7 on: July 17, 2018, 11:52:11 AM »
The main problem I see here is that when player shoots a second bullet, the data for the first bullet is replaced, stopping it in its tracks.  So you either need to 1) Check if a bullet is fired and delete it before creating a new one, or 2) define a bullet type, create a new instance every time one is fired, and iterate over the list using For/Each to move all the bullets each frame.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1128
Re: Really need help with my sad attempt here.
« Reply #8 on: July 20, 2018, 09:41:58 PM »
If you want to manage / update several different bullets, you need to learn to store the instances in a custom type or dim array... Several examples in the codes archives !
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Pakz

  • Full Member
  • ***
  • Posts: 192
    • My homepage
Re: Really need help with my sad attempt here.
« Reply #9 on: July 21, 2018, 02:02:52 AM »
It might be good to learn about arrays and types first. The documentation in b3d is pretty allright.

Basically if you can fire 1 bullet then you just need to create more of the same variables and objects needed for those. Arrays are variables that have a number(depth) you can store enough with them. You could use a currentbullet variable to know which bullet is currently for update of for launching.

Types are a more advanced arrays and contain these fields that are basically variables. One type instance holds all the field variables that you could think of. Each instance of a type is stored inside a list.

So experiment and learn a little bit about arrays and types first :) So dig into the code archives and b3d documentation :)

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Really need help with my sad attempt here.
« Reply #10 on: July 23, 2018, 03:12:23 AM »

All the modes give me the message "Unable to created 3D scene"
for some reason.

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Really need help with my sad attempt here.
« Reply #11 on: July 23, 2018, 03:53:52 AM »
..try to set supported screen size of your monitor without fullscreen...it may be that (when i set full 4K resolution, same error appear)..do something as 800x600 for start , which should work on anything..

Offline Mikey

  • Jr. Member
  • **
  • Posts: 63
Really need help with my sad attempt here.
« Reply #12 on: July 24, 2018, 02:59:02 AM »
I still get the same message.

Does this require some special version of DirectX?

When I change the Graphics3D to Graphics, the program crashes with no message.

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Really need help with my sad attempt here.
« Reply #13 on: July 24, 2018, 06:24:37 AM »
..you have to use Graphics3D..im not sure what sort of problems you actually may have..its hard to say without knowing your machine specifications..far as i can tell, it runs just fine on 10 years old machine (tested just now)..

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Really need help with my sad attempt here.
« Reply #14 on: July 24, 2018, 09:55:15 AM »
..here is the compiled EXE in attachment...copy it where you have extracted media from zip file i have posted before and run it and see is it working..its set to 1024x600, windowed..

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal