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.

Newcomers AppGameKit Corner / Beginner's Raycasting Question

Author
Message
MadTinkerer
9
Years of Service
User Offline
Joined: 21st Nov 2010
Location:
Posted: 3rd Aug 2018 22:27
It's been a while since Trig class, so I have some questions.

I'm trying to use ObjectRayCast to hit an object that the camera is looking at. The first three coordinates are, of course, GetCameraX, GetCameraY, and GetCameraZ. The last three coordinates should be GetCameraX plus something, GetCameraY plus something, and GetCameraZ plus something. Probably something to do with GetCameraAngleX, GetCameraAngleY, and GetCameraAngleZ. I probably have to multiply by something. I hypothesize that hypotenuses may be involved. Possibly the sin() function. But I don't know exactly what to do.
Golelorn
3
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 4th Aug 2018 12:30
I think this should give you the X,Z coords at the center of the screen. Just fill in a value for Y.

smallg
Valued Member
14
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 4th Aug 2018 15:17 Edited at: 4th Aug 2018 15:20
just store the position, move the camera (or a dummy object) forward (MoveCameraLocalZ()), do the raycast from the stored location to the new location, then move the camera back
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
MadTinkerer
9
Years of Service
User Offline
Joined: 21st Nov 2010
Location:
Posted: 4th Aug 2018 15:38
Thanks, guys!

I actually found another answer in Tutorial guide 2, but both of those look like they work as well! Here's an excerpt from my version of the code:



And I didn't even have to do the trig myself. Using the center coordinates of the screen instead of GetPointer also works, if you're not using the pointer to select things and/or not resetting the position of the pointer for the purposes of mouselook.

Login to post a reply

Server time is: 2020-10-21 00:02:53
Your offset time is: 2020-10-21 00:02:53