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.

Code Snippets / [AGK] Heightmap + GetObjectRayCast with WASD + Mouselook

Author
Message
Virtual Nomad
Moderator
16
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Dec 2021 04:59 Edited at: 19th Dec 2021 01:54
Requires attached Heightmap (or any heightmap):


for a nice terrain example with vehicle physics, see ando's offering HERE

Attachments

Login to view attachments
blink0k
Moderator
9
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Nov 2022 05:34 Edited at: 7th Nov 2022 05:35
This uses two objects. A box (camera) and a sphere (lookat). It attaches the sphere to the box and the moves the sphere along the z axis -5 units.
Think of the box as the car cabin and the sphere as the bonnet.

Then it positions the box at the starting point.

In the loop;
(rotation)
1. Depending on the x position of the mouse it will rotate the camera object left or right (Around the Y axis)
2. Depending on the y position of the mouse it will rotate the camera object up or down (Around the X axis)

(movement)
3. Depending on the state of the UP/DOWN/RIGHT/LEFT keys it will move the camera object
4. It gets the height at cameraX and cameraZ from the heightmap
5. it sets the camera to that position and makes the camera "look at" the lookat object


Login to post a reply

Server time is: 2022-12-04 02:05:56
Your offset time is: 2022-12-04 02:05:56