Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to navigate in a 3d enviroment (heightmap)

Author
Message
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 26th Jan 2019 12:00
Hi . Created an object (terrain) from a 3d height map but came across a problem when trying to move about in it . when I turn to the left or right and try to move in the new direction using the rotate camera command I move in the original direction I was facing. I have tried to use rotate object to turn the whole map and this would work but it does not turn at the point of the camera but the bottom left corner . Any help would be appreciated.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 26th Jan 2019 12:03
sounds to me like your character starts off facing the wrong way, try rotating locally when you load or setup your character/camera block
fubar
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th Jan 2019 13:28
@Pfaber1

You need something like this to move the camera :

Quote: "
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 0.2 ) // up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -0.2 ) // down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -0.2 ) // left
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 0.2 ) // righ
t"


if you are moving an object instead of the camera :

Quote: "
if ( GetRawKeyState( 38 ) ) then MoveobjectLocalZ( 1, 0.2 ) // up
if ( GetRawKeyState( 40 ) ) then MoveobjectLocalZ( 1, -0.2 ) // down
if ( GetRawKeyState( 37 ) ) then MoveobjectLocalX( 1, -0.2 ) //left
if ( GetRawKeyState( 39 ) ) then MoveobjectlX( 1, 0.2 ) // right
"


You can find and example here :

https://forum.thegamecreators.com/thread/223498
I'm not a grumpy grandpa
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 26th Jan 2019 19:54
Yes I understand up down left and right and forward . What I am saying is when I move forward it always goes in the same direction not the way I want it to.
puzzler2018
User Banned
Posted: 26th Jan 2019 20:40
I think I know what you mean too cause i have the same issue in Minecraft. When I have resolved the going forward in the direction of the camera is facing then i will post a snippet too.

Your not alone with this..

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 27th Jan 2019 00:26 Edited at: 27th Jan 2019 00:30
Quote: "Yes I understand up down left and right and forward . What I am saying is when I move forward it always goes in the same direction not the way I want it to. "


You need to use a character controller
ie to set one up is like this

then an example of moving sideways



for a complete example please see A small random 3D world of fractals and Kaleidoscopes
on this thread https://forum.thegamecreators.com/thread/222027
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 27th Jan 2019 12:31
Hey puzzler yes that is exactly my problem. If I find out how to do it I'll let you know . I'm pretty much out of ideas at the moment .
puzzler2018
User Banned
Posted: 27th Jan 2019 15:08
Thanks Chafari and Furbarpk too.

Im pretty sure they work great for the task in hand.

Ill quickly knock something up in a while
puzzler2018
User Banned
Posted: 27th Jan 2019 15:19 Edited at: 27th Jan 2019 15:22
Yes the guys were spot on

Are you really sure this is not the effect your after



Click and hold to move camera rotation, press UP cursor to move in that direction
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Jan 2019 16:12
Yeah perhaps Pfaber1 is not presing mouse button .

Here's a compress camera setup that don't need to press mouse.

I'm not a grumpy grandpa
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 27th Jan 2019 21:24
SetErrorMode(2)

// set window properties
SetWindowTitle( "camera turn" )
SetWindowSize( 1366, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1366, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
a=0
b=00
c=0

l=0
m=0
w=10
x=1180
y=0
zoom=0
start:

Print( ScreenFPS() )
if getrawkeystate(32)=1 then setwindowsize(1366,768,1)
if getrawkeystate(32)=0 then setwindowsize(1366,768,0)
Sync()
if getrawkeystate(13)=1 then goto beginning
goto start
beginning:


DeleteObject(3)
CreateObjectFromHeightMap(3,"mappy.png",512,150,512,50,0)
setobjectcolor(3,0,200,0,1)
setobjectposition(3,1000,-150,00)
setcameraposition(1,x,y,zoom)
camerarotate:

setcameraposition(1,x,y,zoom)

setcamerarotation(1,l,b,c)

sync()
if getrawkeystate(87)=1 then zoom=zoom+10

if getrawkeystate(83)=1 then zoom=zoom-10
if getrawkeystate(88)=1 then x=x+5
if getrawkeystate(90)=1 then x=x-5
if GetRawKeyState(77)=1 then b=b+5
if getrawkeystate(78)=1 then b=b-5

goto camerarotate


Hi guys this is what I'm having a problem with . Any help would be appreciated.
puzzler2018
User Banned
Posted: 27th Jan 2019 21:27 Edited at: 27th Jan 2019 21:30
OK - see what we can work with - can you attach the mappy.png file so we can at least see a map from the PNG

Sure we will come back soon with a resolvement.

I see you "havent"really changed any of your source to what we suggest



Thats the issue..

We can help as best we can Im sure
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 27th Jan 2019 22:21
Here's a copy of the mappy.png file. This is just an experiment to see how it all works. My first attempt at learning some 3d stuff.

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 27th Jan 2019 22:26
Ok cool - bear with us

Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 27th Jan 2019 22:28
Press return to start then the keys are w and s , z and x , n and m , . I did try changing my code around but ended up with the same results ie when I turn the camera and trying to go forward I don't move in the direction of the camera .
puzzler2018
User Banned
Posted: 27th Jan 2019 22:34
Give me a sec

Hows this


Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 28th Jan 2019 00:05
Well changed my code a bit. I'm not using the mouse just the keyboard. Here it is so far haven't worked out how to move forward but will keep experimenting until I find out .

if getrawkeystate(83)=1
MoveCameraLocalY(1,5)
endif

if getrawkeystate(87)=1
MoveCameraLocaly(1,-5)
endif
if getrawkeystate(88)=1
MoveCameraLocalX(1,-5)
endif
if GetRawKeyState(90)=1
MoveCameraLocalX(1,5)
endif
if GetRawKeyState(77)=1
RotateCameraLocaly(1,5)
endif
if getrawkeystate(78)=1
rotateCameraLocaly(1,-5)
endif
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Jan 2019 00:35
you need to use a character controller otherwise there is allot of mathematics required to get the directions right
that's the reason we have character controllers. (please see my last post) character controllers don't move the same way
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 28th Jan 2019 00:42
Thanks everybody I've now got it all working . This is the final bit of code I came up with . Couldn't of done it without the help of you guys . Fubar I'll check out character controllers next . Thanks again. if getrawkeystate(83)=1
MoveCameraLocalZ(1,5)
endif

if getrawkeystate(87)=1
MoveCameraLocalz(1,-5)
endif
if getrawkeystate(88)=1
RotateCameraGlobalx(1,-5)
endif
if GetRawKeyState(90)=1
RotateCameraglobalx(1,5)
endif
if GetRawKeyState(77)=1
RotateCameraGlobaly(1,5)
endif
if getrawkeystate(78)=1
RotateCameraGlobaly(1,-5)
endif


fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Jan 2019 00:52
moving the camera left right forwards backwards is all you will get that way
but no good for player movement which 99percent of the time your rotated
someway that's why you need a playercontroller and use the player controller
movement commands because they handle heavy mathematics like the vectors
needed to calculate the positioning of the player. which you then just attach
a camera to. sorry if I sounded harsh but that's why Paul created character controllers
in AppGameKit so you can have true player movement. Unless ofcourse you just want to
move left move right or forward or backward even tho the land may be rotated
it wont work the way you want. Besides land is a big big files and shouldn't be rotated
only the playerobject in the direction you want

GOODLUCK
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Jan 2019 01:00
I have never seen true 3d player movement in here without the use of a character controller

and there is some dam good programmers in here who excel in vector mathematics
it doesn't mean it cant be done just means theres no point and the ones who are capable of
calculating the vectors don't because the character controllers work superbly
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 28th Jan 2019 08:04
ok thanks fubar will definitely learn about character controllers next . Bonjour

Login to post a reply

Server time is: 2024-10-01 01:25:38
Your offset time is: 2024-10-01 01:25:38