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
18
Years of Service
User Offline
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
11
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


Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Apr 2023 03:00 Edited at: 21st Apr 2023 03:11
now with collectables!

note: standard 3D rays don't like rotated boxes in my experience; consider physics rays or at least light bullet collision.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 22nd Apr 2023 17:48 Edited at: 22nd Apr 2023 17:50
Third person setup for this snipplet

Login to post a reply

Server time is: 2024-11-17 22:46:35
Your offset time is: 2024-11-17 22:46:35