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 Studio Chat / Align 3d object to heightmap

Author
Message
MMT
6
Years of Service
User Offline
Joined: 12th Mar 2018
Location:
Posted: 9th Oct 2022 16:20

Scratching my head on this one. So basically let's say I have a slope in the terrain and a box. I want to adjust the rotation of the box so it fits the heightmap. I don't want to use 3d physics, not worth the hassle.

basically my approach was to get the heights at the four corners. Then I can sorta take the average and elevate half the size of the object.

But my attempts to calculate a fitting rotation resulted in funny stuff.

Has anyone something ready for this?

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 10th Oct 2022 03:48
you could try casting a ray at the heightmap object and getting its normals and going from there as in the user example HERE.

otherwise, it's going to be somewhat of a "hassle" no matter how you go about it and the physics system really isn't any more of that than what you see in that example. ie, a quick setup of the world, giving the box a dynamic body and sending it on its way.

meanwhile, how precise are you expecting the results? if some terrain penetration is ok, you should be fine with the normals method. for better precision, bullet3d is the easier way to go about it, i expect.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 10th Oct 2022 18:43 Edited at: 10th Oct 2022 18:44
Hi there. In my thread " Chafari tricks" I made an example " align object to terrain" that can do what you are looking for. It was made for Agk clássic but I suppose It works in studio. I hope It can help.
I'm not a grumpy grandpa
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Oct 2022 02:24 Edited at: 11th Oct 2022 02:30
Quote: "I made an example " align object to terrain""

ah, i remember that one now.


i should mix it with THIS

@MMT, let me save you some digging
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 23rd Oct 2022 12:39
Bit of a late response here.

This car body rotation uses the 4 ray average method with one at each corner.
https://forum.thegamecreators.com/thread/228181

Virtual Nomad points out another way here and I used it to set the correct angle of bullet holes.
https://forum.thegamecreators.com/thread/228248
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Nov 2022 15:33
Essentially you need to determine the normal of the polygon your object is over. You can do this if you have 3 points of reference for the polygon.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-05-04 08:29:42
Your offset time is: 2024-05-04 08:29:42