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 / 3D Camera Collision

Author
Message
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th Mar 2016 19:48
Before I try and make my own, has anyone made a 3D Camera Collision routine? I'm having loads of trouble with the various raycasting functions decidedly NOT colliding with things!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Mar 2016 05:47
I haven't yet but the collision commands are sparky's collision almost exactly so you should be able to knock some sphere sliding code (I'm pretty sure that's all in there) pretty quick being an old DBPro
Using AppGameKit V2 Tier 1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 31st Mar 2016 10:11
I could, but like I said, I was running into troubles with the raycasting and spherecasting commands.,

I'll keep working on it and get something knocked up, hopefully it'll be quick!
Cor
AGK Developer
13
Years of Service
User Offline
Joined: 19th Dec 2010
Location: Its a trap!
Posted: 31st Mar 2016 15:49 Edited at: 31st Mar 2016 16:30
Take a look at the example that comes in the 3d folder that is an fps camera in the metro theater pack. It has a great sliding collision code and its what I'm using in my zombie game.


edit:
here is the code i pulled from the example for you
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 31st Mar 2016 18:00
You can also try this example

It was done in an older version of AppGameKit so uses the old directional light command but other than that it should work in the latest version.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Apr 2016 14:15
@Cor: Thanks I'll try that again, I don't know why I didn't use this method for the camera, as I used this method originally for the player. (My game was originally based on the Metro demo)

@29 games: The MoveCameraLocalZ command does not apply collision. That's what I'm trying to create. (I am however currently using this command to move the camera away from the player after orienting it to the characters head angle.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2016 14:56
Cor, I tried the function you gave me, but it doesn't seem to work either. Maybe Physics objects are removed from the standard object list and cannot be used with any of the raycasting commands.

I'll have to ask.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 2nd Apr 2016 20:41
Hi Mobiius, yes the command MoveCameraLocalZ() doesn't have any collision detection but the example is an FPS demo that deals with collision (no I don't know why I put the example with this command, I was probably having an off day).

I might be able to knock up a simple 3rd person camera example. The best way is to sphere cast from the character's head to the maximum distance the camera is behind the character. If a collision is detected then reposition the camera according to the collision coordinates.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Apr 2016 23:00 Edited at: 2nd Apr 2016 23:02
Quote: "The best way is to sphere cast from the character's head to the maximum distance the camera is behind the character"

That's what I'm doing, but nothing I've tried has worked.



This is currently where I'm at. (You can see what I've commented out as it isn't doing what's expected.

This is starting to annoy me!
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 4th Apr 2016 22:13 Edited at: 5th Apr 2016 02:56
the example that comes with agk is flawed. (The one with the metro studio) If you load your own level into it with hills and slopes the camera slides down them without moving.

The problem is if you have slanted ground your character or / camera will slide down it. that code only works for flat ground only.
It needs an adjustment to allow some degree of angle climbing and without making your camera slide down every slope.
Im going to see what I can come up with... unless someone else has figured this out already.


edit: actually its a quick fix! I think...

check for sliding collision on x,z only when your character is moving... check y all the time.
Ill do up some code to see if that works

edit: I was close!

so when you do the first sphere collision check it should be a bigger radius such as 45 and only adjust x,z values
then do another sphere collision check with a small radius such as 10 but subtract some units for the check so your characters not inside the floor
then do another sphere collision check with a small radius such as 10 but add some units for the check so your character does not go through a ceiling.

this fixes sliding on small slopes and only slides or unable to climb on big slopes.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Apr 2016 10:03
The problem I'm having is that I'm not getting a collision at all, so there's nothing to slide against.

I don't know why, but it's proving very difficult to resolve.
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 5th Apr 2016 13:30 Edited at: 5th Apr 2016 13:31
Its always hard to get collision perfect.

i do something like this, sorry just a copy paste nothing generic:


playerheight# = the height of the player you like.

I do multiply checks to find a spot for the camera , and save the last known good spot , this way if you somehow get stuck inside a object or something like that you can always move to lastgoodx#, (if realchecks is always 4 for sometime)....
Sometimes you need more then one check , to make sure that the new position is ok ( after you set the new groundy# ).

I use a ObjectRayCast to find the ground , this will work on objects and terrain so you be able to leave the terrain and move up on a objects stairs. ( also allow you to go into a tunnel without ending ontop of the objects , but stay in the tunnel ).

You need to adjust these to settings: ... ObjectSphereSlide ... playerheight#/2.2... and ...phdiv# = (playerheight#/3.0)... to fit your needs.

Also i ALWAYS make a dummy object ... debugsphere = CreateObjectSphere((playerheight#)*2.0,9,9) , and place it infront of the camera using the camera xyz , so you can SEE what ObjectSphereSlide is checking, and exactly know what to expect. this makes it MUSH easier when you make the collision.
Start by moving and doing collision on the debugsphere ( setting the camera just behind like 3rd view ) , this way you SEE what need to be changed. The CreateObjectSphere should be the exact same size as ...playerheight#/2.2.. * 2.0 ( ObjectSphereSlide is radius ).

Hope it helps.
best regards Preben Eriksen,
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Apr 2016 14:12 Edited at: 5th Apr 2016 14:13
Thanks, but that code won't work on physics objects.
Stab in the Dark software wrote: "If you are creating your static world/level with Create3DPhysicsStaticBody() then you would need to use the 3D physics commands on this page for ray casting."


And that will only work when checking straight down. I need all round collision detection as the camera can be moved anywhere.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 5th Apr 2016 19:25
Is your camera a physics object.... Most likely not so i would just use the regular sphere slide commands for your camera. Make sure the collision mode is set to 1 for the camera object and your world object.

Dunno about the physics commands but the others do work perfectly and i dont need to use any crazy trig to figure it out or any vector stuff.

I think you should be able to use both collision systems side by side if setup correctly.

Id also code in a curve value command so the camera sphere does not jerk from position to position.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Apr 2016 19:47 Edited at: 5th Apr 2016 19:49
The regular sphere slide commands apparently don't work on physics objects.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Apr 2016 00:02
humm... that sucks!
sorry I couldn't help.

hopefully sitd can find some time to get us all some examples with some documentation to go with it.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 6th Apr 2016 13:37 Edited at: 6th Apr 2016 16:23
It would seem that TGC ran out of funding for things like examples with documentation.
I am creating the examples on my own, as I get time I will add more. The next example
will cover the ray casting commands.

Quote: "The regular sphere slide commands apparently don't work on physics objects."


Paul's sphere slide commands should still work. What I meant is that the 3D physics commands do not work in
conjunction with the other sliding collision commands. For example the 3D physics ray cast commands will only return a hit on a 3D physics object.
The 3D physics commands create a collision shape for the object that is only used by the 3D physics commands.
I believe the sphere slide commands use polygon collision on the objects so they should still work for your camera.

P.S. Come on guys vectors are not that complicated all the math is done for you using the vector commands.
If you are creating a 3D world you can not get away from vectors you need them.
The coffee is lovely dark and deep,and I have code to write before I sleep.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Apr 2016 14:03
Thanks sitd.... Didnt know tgc ran out of funds for ya. They should consider restoring or making the examples themselfs.

And vectors... I know very little. Thats whats great with these commands as they do most of the vector math behind the scenes.

Id use the sphereslide commands for your camera !

Login to post a reply

Server time is: 2024-09-29 13:26:06
Your offset time is: 2024-09-29 13:26:06