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 / [SOLVED] GetObjectRayCastXXXX

Author
Message
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Feb 2021 20:54
I have got some confusing behaviour going on with regards to X/Z positions returned from GetObjectRayCastXXX

so my setup is a plane with a grid shader applied, I use the standard code to get the 3D position from the mouse, cast a ray from the camera, this works fine for collision checking but when placing items in the world the end positions become less reliable the further the mouse is away from the center of the screen so I turn my grid plane into a sensor and use GetObjectRayCastXXX to get the exact intersect location which works perfect, almost

while placing items and testing this was fine, everything goes where I want it no matter where on the screen its located, then I added a virtual grid (3 dimension type array) and I grab the intersect point of the ray, the grid plane is offset by half its size so the upper left sits at 0,0 so in theory a simple math to get the grid cell index from the intersect location, easy right??

the z value increases along the x axis and the x value increases along the z axis which has been confusing the life out of me for the last 2 days because until I printed the values to screen I was unaware this was going on but everything I have coded just works

If I put the camera underneath the plane and rotate it 90 degrees and I get the behaviour I expect (x on the x axis and y on the y....)

So I ripped my code apart looking for bugs or at least a reason why, I suspected I mixed up a x and z value somewhere but no, backtracked and made every single function that uses the grid system all feed the same variables from the main loop and still the axis seem to be inverted

So following the path of logic I deduce that my locations are coming from GetObjectRayCastXXX < does this function somehow invert the x/z values, are the objects stored in memory this way <<<<????

I have started coding a system for drawing roads and paths and I use this grid system to check neighbouring cell types and place the required road section, and here is where its going to cause problems

I use a set of functions like below


for left, right, up, down, but now up is not up, left is not left because of the GetObjectRayCastXXX inversion, sure I can tweak the params to reflect my (up is left and down is right) world but I dont want to run into problems further down the line because of this, I need to understand why this is happening before I can think a way round it.

Any ideas?, It has to be a memory allocation thing right? I'm confused!!! Help!!!! lol



The author of this post has marked a post as an answer.

Go to answer

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Feb 2021 21:32
The vector needs to be the vector at the center of the camera, applied to the mouse position (I think)
Note that 100000 is the end of the RayCast. If your distances are greater then make it larger

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Feb 2021 23:17
Thanks for the function, I seem to be getting even more inconstant results using it though, I'll study the code and see if I can apply anything to my own code, I get what your saying about normalizing the camera and mouse vectors into a single vector for the ray, that makes sense and probably why I get inconsistent results when the mouse is far from the center of the screen.

I'll experiment a bit and see what I can get working
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Feb 2021 00:32
This post has been marked by the post author as the answer.
This is an app i wrote using that system
Right click drag to move the plane
Ctrl+Right click to rotate the plane.

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Feb 2021 05:25
Thats a pretty nice prototyping tool you got there, although I got my original system working there is certainly a few things to learn from your code, I like that you can move the grid and still get correct positions I wonder how that system will play with my pathfinding system, I will have a play with your project and see what I can learn from it

Thanks for your help

Login to post a reply

Server time is: 2024-03-28 22:47:58
Your offset time is: 2024-03-28 22:47:58