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 / detecting collision between two objects

Author
Message
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 4th Feb 2019 14:39
Hi created my 3d world and was wanting to know how to detect a collision between two objects or in this case the camera and the terrain.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 4th Feb 2019 14:42
You use a raycast. Raycast from the camera position down toward the ground, detect a collision.
puzzler2018
User Banned
Posted: 4th Feb 2019 14:47
I did something with objects around cameracusing rayxasts

https://forum.thegamecreators.com/thread/223640

Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 4th Feb 2019 20:03
could you please explain a bit more about the raycast command and how to use it.
maybe a line or two of code.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Feb 2019 20:08
this function checks for collision between two objects and returns one if there is a collision between then
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 5th Feb 2019 21:40
Has anybody got the knowledge to use the camera to navigate and use raycast. What the hell is raycast.
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 5th Feb 2019 21:42
just when everything was going well got some great levels lined up. Need to get this right .
puzzler2018
User Banned
Posted: 5th Feb 2019 22:07
Are you still struggling even with the examples we have provided
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Feb 2019 23:09
Quote: "Has anybody got the knowledge to use the camera to navigate and use raycast. What the hell is raycast. "


There are many camera commands

such as
movecameralocalx(1,ammount)
movecameralocaly(1,ammount)
movecameralocaly(1,ammout)

which is great for moving a camera but if you want player movement with the camera

use a character controller the math/physics is all done for you and will work faster that way as its done in c in the backbones of AGK
then position and rotate the camera according to the player object. You could place an invisible object rear of the player for example
and fix it to the player and use that invisible object for camera positions

Collisions are very hard to detect in 3d and not as simple as they are for spirtes. So a raycast is used to determine if an object exists
in a particular area
fubar
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 6th Feb 2019 10:08
ok i'll study the example . Thanks for the input.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Feb 2019 12:13 Edited at: 6th Feb 2019 12:18
If you ONLY want to know about a collisions between the camera and a terrain made from a heightmap then the fastest way is.....

GetObjectHeightMapHeight ( objID, camerax, cameraz ) and compare this to the camera Y value.

The example project named "Terrain" that comes with AppGameKit uses this function to allow you to move over the ground but keep withiin 1 metre of it as you move the camera.

That function is only useful for collisions into the terrain though. As has been said above, object raycasts can be more useful to detect collisions with any 3d object. The objectslide results give where the camera should be to keep it from moving into the object.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 7th Feb 2019 02:04
A raycast is a mathematical line from a given point extending in a given direction for a given length.

This will determine if an object is intersected by this line and can give you additional information about the object and interaction such as the obj3ct number, the angle at which it was hit (hit vector), the angle along the face that was hit (slide vector), the perpendicular angle of the face that was hit (normal vector) and so on.

Even when using a physics engine to handle collision, raycasts can still be very useful for determining line of sight, AI behavior, user interaction with the world space and so on
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
haliop_New
User Banned
Posted: 7th Feb 2019 02:18
Pfaber1 hang in there! we all know it could be tough to understand sometimes, but once you'll get the hang of it there is no 3d game you cannot build with AGK.
in the example shown about the 3d collision with 2 objects you can simply change the object to a camera they have mostly the same commands about X, Y, Z positions and rotations so it should not really be a problem..you just need to grasp the idea of it and you are done.
Pfaber1
6
Years of Service
User Offline
Joined: 7th Jan 2018
Location: England
Posted: 9th Feb 2019 17:58
Well I eventually managed to get my object going over the hills instead of through them . used getheightmapheight made loads of mistakes but eventually got the result I was after .



if getrawkeystate(73)=1
MoveobjectLocalZ(1,54)
if GetObjectHeightMapHeight(3,getobjectx(3),getobjectz(3))<=1000
moveobjectlocaly(1,5)
movecameralocaly(1,5)
SetObjectPosition(1,getobjectx(1),GetObjectHeightMapHeight(3,getobjectx(1),getobjectz(1)),getobjectz(1))
Print (x)

endif
endif

This is what my code looks like . I tried all sorts of stuff to get this to work. Anyway thanks guy for all your help . Next it's gonna be the raycast thingy. I guess when I've nailed that I'll be ready to make a start.
could take a while . Thanks once again


Login to post a reply

Server time is: 2024-11-05 22:57:07
Your offset time is: 2024-11-05 22:57:07