Moving Platform Collision Detection
by Jason Davis · in Torque Game Engine · 05/23/2006 (3:31 pm) · 138 replies
Okay, I've searched the forums to no avail. I have a dts object scripted to move upward when the player steps onto it (via a scripted trigger.) The dts object is a simple cube. Even though the player detects the collision mesh when stepping onto the cube and the cube begins to visibally rise, the player continues to stand where the old collision mesh was. I have tried everything I know to do... anyone have any help or resources they can give me? Thank you so much and I will look forward to a response.
#122
i'm a bit confused tho,
how does the raycast help attach/detach ?
oh, you're probably doing the raycast only in onLand() (onImpact?) or whatever, and automatically detaching on jump ? nice.
07/02/2006 (10:15 am)
Possibly script could provide the desired attachable typemasks ?i'm a bit confused tho,
how does the raycast help attach/detach ?
oh, you're probably doing the raycast only in onLand() (onImpact?) or whatever, and automatically detaching on jump ? nice.
#123
In the script callback is where the actual attachment occurs.
If the ray cast returns no object, or an object not of the typemask, AND the player is currently attached to something, it detaches it from it's parent.
07/02/2006 (10:17 am)
The ray cast is checking what the player is standing on. From there it determines if the object is of the correct typemask, and then does a script call back.In the script callback is where the actual attachment occurs.
If the ray cast returns no object, or an object not of the typemask, AND the player is currently attached to something, it detaches it from it's parent.
#124
expanding on the above, it'd be nice to enable script to provide the typemasks. eg, use a Con::GetIntegerVariable() in the engine side, and in script have something like "$platforms::validTypemasks = thisOne | thatOne | alsoThisOne;"
07/02/2006 (10:37 am)
Right. but i'm curious when/how often you're doing the raycast.expanding on the above, it'd be nice to enable script to provide the typemasks. eg, use a Con::GetIntegerVariable() in the engine side, and in script have something like "$platforms::validTypemasks = thisOne | thatOne | alsoThisOne;"
#125
Right now its just doing a call back based on the platforms datablock.
function RiotBody::onMovableSurface(%this,%obj,%col){
error("surface is "@%col);
if (%col.getClassName() $= "PathShape")
%col.attachchild(%obj);
}
or something like that.
07/02/2006 (11:10 am)
The raycast is being done in the players process tick. but it could also be place in interpolate tick as well.Right now its just doing a call back based on the platforms datablock.
function RiotBody::onMovableSurface(%this,%obj,%col){
error("surface is "@%col);
if (%col.getClassName() $= "PathShape")
%col.attachchild(%obj);
}
or something like that.
#126
07/02/2006 (4:23 pm)
Ok... what i think stephen was sugesting is doing something like each tick subtract the previous translation from the current translation of the platform and take that difference and add it to the players current location instead of setting the players to the same as platform.. that way the platform is only effecting the player rather than conforming the player to the platform... my only other idea is maybe create a new class inherited from the terrian and make it moveable... but again just shots in the dark i dont really know the source of the engine that well... i've almost gotten my computer back up to a usable state.. so as soon as i get VS installed i can start digging my self
#127
That's how i'm free to move on the platform and jump off, and back on it again. I can even jump from one moving platform to another moving platform.
07/02/2006 (4:38 pm)
Hmmm well that's exactly how it's working. the player isn't being set to the same position as the platform at all. I get the difference from the tick to the current render transform of the platform, and add that to the players.That's how i'm free to move on the platform and jump off, and back on it again. I can even jump from one moving platform to another moving platform.
#128
Looks good!
07/02/2006 (5:02 pm)
Hmmm... You've got a very interesting way of going about this...Looks good!
#129
07/02/2006 (6:09 pm)
If you can mount any scenebase object, why don't you just mount a trigger onto the platform, and use that for determining if the player is on it or not?
#130
But what if you want to jump from your bi-plane, onto a floating castle that orbits the moon?
You'd have to set it up in a different manner since you may not know exactly where you will land.
How i have it setup now will check any object you are standing/landing over.
What if you want to jump on a circular platform? can't make circular triggers now can we?
At first i had it mounting via an oncollision callback. but that won't work if you just walk onto the object. there's no collision happening.
07/02/2006 (6:15 pm)
Could do that too. however, i decided against it. it'd require you to place a trigger on every platform or whatever object you wanna attach to.But what if you want to jump from your bi-plane, onto a floating castle that orbits the moon?
You'd have to set it up in a different manner since you may not know exactly where you will land.
How i have it setup now will check any object you are standing/landing over.
What if you want to jump on a circular platform? can't make circular triggers now can we?
At first i had it mounting via an oncollision callback. but that won't work if you just walk onto the object. there's no collision happening.
#131
07/02/2006 (6:28 pm)
I suppose... though you could at least maybe not do the raycast checks if the player is immobile? I just worry about the efficiency, though really raycasts aren't _that_ bad, and I have some pretty hacky code using them like that myself.
#132
07/02/2006 (6:36 pm)
It's a 0.6 unit raycast every tick. that's probably too long as it is anyhow. just need to check from a tiny bit above the player position down a little.
#133
07/02/2006 (6:38 pm)
Ah, nowwww i understand. i didn't realize it was a *short* raycast. of course! nice. 0.6 seems a bit much, even, but i'm sure you've tuned it.
#134
Man, anyone else notice how long this thread has become :P
I'm still SLOWLY working on cleaning up the code. I've never made a resource using C++ before so i wanna try and organize this a little bit.
If anyone wants to have a crack at these files, hit me up via AIM or Yahoo and i can transfer some files and help you set it up. Make sure you're a SDK owner or i won't send them to you :)
07/02/2006 (6:44 pm)
Yeah, you want the ray cast to only really hit something that you will come in contact with very soon. a bit of tweaking will be needed so you don't attach too soon or what not. 0.6 was just an experiment. but that's still... what.... 1.5 feet? it should be scaled back even further really.Man, anyone else notice how long this thread has become :P
I'm still SLOWLY working on cleaning up the code. I've never made a resource using C++ before so i wanna try and organize this a little bit.
If anyone wants to have a crack at these files, hit me up via AIM or Yahoo and i can transfer some files and help you set it up. Make sure you're a SDK owner or i won't send them to you :)
#135
Code is just a click away.
www.garagegames.com/mg/forums/result.thread.php?qt=47074
07/03/2006 (3:36 am)
Moving this thread onward to the private forumns everyone :)Code is just a click away.
www.garagegames.com/mg/forums/result.thread.php?qt=47074
#136
-Surge
edit:Spelling:(Typing so fast I speelledd every word wrong.heheh)
07/04/2006 (4:58 am)
Thank you so much Ramen.-Surge
edit:Spelling:(Typing so fast I speelledd every word wrong.heheh)
#137
- Jason
07/06/2006 (9:35 am)
Not that this is the final conclusion of this thread, but I started this thread without a lot of hope... but Ramen has come to the rescue with the source code to make the moving platforms a reality! Thank you Ramen, your hard work is so very appreciated!!!- Jason
#138
Once again, here's the forum for the answers:
www.garagegames.com/mg/forums/result.thread.php?qt=47074
08/17/2006 (10:07 am)
I just tested out Ramen's moving platform code. It works beautifully, just what I wanted!!! Thank you Ramen, you are a genious!Once again, here's the forum for the answers:
www.garagegames.com/mg/forums/result.thread.php?qt=47074
Torque Owner Cinder Games
I'd like people opinions on how this should work. I currently have it only able to attach to pathshapes. but it can be changed to vechicles, players, and more. I have it doing a script call back right now. That way you can detemine if you actually need to attach to it or not.