I have my terrain and a problem.

Started by Pfaber11, July 20, 2022, 22:53:59

Previous topic - Next topic

Pfaber11

Ok so I have my terrain and I put a camera in the middle of it . The problem I have is this I move forward fine then I turn to the left or right and the camera looks in the right direction but continues to travel along the original path and not where I'm looking. I'm gonna put some code on the screen so you can see and possibly make some suggestions.

maincode:
   ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
      MoveEntity(25,0,0,2,#PB_Relative)
      MoveCamera(0,EntityX(25),EntityY(25),EntityZ(25)+2)
     
    EndIf
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_A)
      RotateEntity(25,0,1,0,#PB_Relative)
      MoveCamera(0,EntityX(25),EntityY(25),EntityZ(25))
     
      EndIf
      jump61:
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_D)
      RotateEntity(25,0,-1,0,#PB_Relative)
      MoveCamera(0,EntityX(25),EntityY(25),EntityZ(25))
     
     
     
    EndIf
MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0))+10 , CameraZ(0), #PB_Absolute) 
  RenderWorld() 
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

DaiHard

Looks like your "move" instruction always moves you 2 in the z direction?

I'd expect to see something like
MoveEntity(25, 2 * COS(heading),0,2*SIN(heading),#PB_Relative)

Forgive me if the syntax is wrong - I don't know this language - but the gist is that you need to keep a record of the heading of the entity, and then move in the X direction by the cosine of that angle, and (assuming Y is vertical, as I conclude from the rotation)  in the z direction by the sine of the angle - that's assuming "heading" is a conventional angle, i.e. 0 points along the x axis, with increasing angles moving counterclockwise.

Pfaber11

I solved this by moving the code to the end of the main loop.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Well I solved the original problem and now have another . when I use entitylookat it turns and looks at the camera but then when I then try to move the entity forward it goes off in the wrong direction.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

I create my terrain then put my entity on it . When I rotate the entity and then try and move foeward it travels forward in the original z direction . Any ideas how I might solve this . Thanks for reading .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#5
Well I've figured it out and all is again going smoothly. I was starting to think this was not going to work out but I am feeling pretty good now and I have put together a 150 line program for myself with sprites and entity + terrain and the such . I am now at the same level as I was with AGK and it took me 3 months and 10 days to accomplish. There were times when I wanted to quit and go back to AGK but I'm now glad I didn't . I love AGK and if they bring out a successor to Studio maybe I'll take a look but I doubt that's gonna happen for some time and I think PB is the last language I'm gonna learn so this has to be the last and best choice for me . I suppose I was expecting too much from AGK and at the end of the day they do call themselves The Game Creators . I think if someone wants to learn real game making then AGK is a very good step in the right direction . Mind you I have come across a couple of people on here who say they can't get on with it so I suppose one persons medicine is another mans poison . Have a nice day.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

This is the answer to this problem. If you add #PB_local to the end of your forward and reverse code like so:

     
     ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
      MoveEntity(1,0,0,-2,#PB_Absolute|#PB_Local)
    EndIf
   
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_S)
      MoveEntity(1,0,0,2,#PB_Absolute|#PB_Local)
    EndIf



This had me stumped for a few days until some good people shared their knowledge with me on the PB Forum.
I hope this helps someone as it did me . Have a nice evening
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz