Game Development Community

Platforms Players can Ride Version 1.1

by Cinder Games · in Torque Game Engine · 01/27/2007 (4:34 pm) · 268 replies

Platforms Players can Ride Version 1.2!!!!!!
with Dynamic object Attachment
###################################
##This post has been edited and updated 2/13/07 ##
##################################

subvoicestudios.com/~ramensama/TorqueDynamicAttachment.jpg

Here's the new and improved files you'd need.
Version 1.2
subvoicestudios.com/~ramensama/torque1.5.2.zip

1.7.2008
What's new? There are several new features and improvements.

1) Removed or reduced jitter caused by multiple players on a platform
2) Support for new items on platforms. Now Items, Shapes, lights, particle emitters, and possibly others!
3) Object to object Attachment. Players can now attach Items, shapes, etc to them. Even the attached objects can attach more objects to themselves!
4) Reduced the number of code changes.... a little.


This must be extracted in the base torque directory where it's installed...
c:/torque

or whatever. it's designed to simply overwrite a stock install of torque.

Afterwards you must add pathshape.cc and pathshape.h to your project in visual studio or whatever.

img292.imageshack.us/img292/9507/addexistingxy9.gif

To attach an object, you must use this syntax:

ParentObject.attachChild(ChildObject);

So if you want to attach an item to the player, move the player towards the object, press F11 to get the object ID. Press ~ and type in $player.attachchild(ObjectID);

The item is now attached to the player.

$player.detachchild(ObjectID); is how to remove the object.






Ancient Versions of the code can be found here.
These are version 1.1, not the newest version and probably have bugs that the newer code does not.
Here's a link to the new updated code. It's for torque 1.4...
subvoicestudios.com/~ramensama/torque.zip

And for Torque 1.5
subvoicestudios.com/~ramensama/torque1.5.zip
#221
04/10/2008 (10:01 am)
I need more time to learn this stuff, hopefully weekend isn't crowded.
We know the current location of the pathshape, it's current destination, it's heading, and the speed it travels along that path. Any problem with building a velocity from that info?
#222
04/10/2008 (10:11 am)
Pretty sure you could figure out how to add in a velocity variable the same way it's collected for other objects. I'll see this weekend or so about figuring out how to add that in.
#223
04/12/2008 (4:44 am)
Any news on making a player a child of a shape (vehicle) in 1.5.2? Tried implementing the code way up there, but got a compile error! Really awesome resource btw!
first, when adding the code you supplied, i get an error about updateParentedTransform()
when adding a void function in sceneObject.h removes this, a Linker error occurs!
any ideas? =)
#224
04/27/2008 (6:45 pm)
Bah. This resource makes my game crash when it tries to load the datablocks, about an eighth of the way there. Any ideas as to what went wrong? Console's not showing anything odd, as far as I can tell.

EDIT: Anyone? <_< >_>
#225
04/29/2008 (11:21 pm)
Works like a charm. Great resource. Although I changed it a bit because I wanted to mount on another Player (ie. AIPlayer). Now to solve the shadow not being casted to the mounted platform. Anybody have any ideas? Thanks a lot.
#226
05/13/2008 (10:59 am)
I am getting an error stating that is is unable to instantiate con object PathShapeData

could anyone help with that i have the .cc and the .h files initialized
#227
05/13/2008 (2:25 pm)
Sounds like you didn't add the pathshape.cc and pathshape.cc files to your project.
#228
05/14/2008 (12:32 pm)
I have them initialized in the gamebase.cc in the engine folder so im assuming that there is another place i need it
#229
05/14/2008 (2:57 pm)
I don't understand what you mean by "initialized" you add them to your visual studio project. like the picture in my first post indicates. But it may not build unless you have those added. Another thing might be not adding the pathshape.cs files into the proper cs file. But the files i provided should have overwritten everything needed, except for adding the pathshape.cc and .h file to that visual studio project.

Also, make sure you build in relese, not debug.
#230
06/02/2008 (5:28 pm)
I am still having some trouble with it and i would like to know your project settings for this because i have never used visual studio in conjunction with torque

sorry about the stupid newbie questions
#231
06/09/2008 (1:30 am)
The resource is not working as good as I thought. Occasionally the player can't be attached even if it is on top of the platform. It just slips from the platform's surface and falls down. Or it passes through the platform and falls down. But most of the time it worked though. FYI, I use a moving AIPlayer as the platform. So the player is trying to attach to a moving object. Anybody know why does this happen? Thanks in advance.
#232
06/09/2008 (1:35 am)
If the player isn't attaching how you like, you into how it actually goes about it. It does a ray cast from the center of the player object down. so if you jump onto the platform but the center of the player isn't over it, then it might cause this problem. you could set it up to attach however and whenever you like. I simply chose a raycast which triggers a call in script to do the attachment.
#233
06/09/2008 (8:53 pm)
Yeah, I noticed it. BTW, is that ray casting method named UpdateAttachment()? The problem of having only a ray cast from the center of the player is it will return false if the player is actually on the edge of the platform (the ray cast returned false because there's nothing below the center of the player, yet the bounding box of the player and platform can still collide). And IMHO this is what my current problem is. I don't quite understand how the player's collision detection works but AFAIK it's based on ray casting, right? CMIIW. Maybe I'll add some of your ray casting method so that it would make a few additional ray casting from the edge of the player's bounding box. Still don't know how to do that though. :D
#234
06/09/2008 (8:57 pm)
I don't pretent to understand player collision either. Try adding some more rays as you suggested. See if that makes any changes. alternatively, you could do some experiments and omit the ray casts, and instead have ti attach via a oncollision call. This is not practical since the player can hit the objects from more then one direction.

But there is another check somewhere to detach the player if they're not on the platform.
#235
06/11/2008 (2:50 am)
Have tried changing the code to ray casting from each edge of the bounding box. But it still give the same result, although not as often as it used to. My assumption is it got something to do with the FPS. So maybe because it's somewhat lagging (there're tons of object in a scene currently and my computer is slow as hell), the data between server & client doesn't match. Maybe even if the client rendered the scene as if there's a platform below, the server doesn't. I'll have to look more for this issue. BTW, how do you use "attachChildAt()" method? I need to directly attach a child to the platform, beside the player, and AFAIK the way to do it is with that method, CMIIW.
#236
06/11/2008 (7:48 pm)
Found a bug (maybe). If the parent (platform) is moved via the setTransform() function, the child is not following the move. I noticed it because my code below:

function LogDBlock::onAdd(%this, %obj)
{
		//20080611: Add snake on the log
		%XForm = %obj.getTransform();
		%posXY = getWords(%XForm, 0 , 1);
		%posZ = getWord(%XForm, 2) + 1;
		%rot = getWords(%XForm, 3, 6);
		%snakeXForm = %posXY SPC %posZ SPC %rot;
		%snake = new StaticShape(){
			dataBlock = "SnakeDBlock";
		};
		echo("------LogDBlock::onAdd(): XForm:" SPC %XForm);
		MissionCleanup.add(%snake);
		//%snake.setMoveSpeed(0);

		%snake.setTransform(%snakeXForm);
		%obj.snake = %snake;
		%obj.attachChild(%snake);
		//%pos = %obj.getDatablock().boundingBox;
		//%obj.attachChildAt(%snake,"");
		
}

I use a log as the platform for the player and on top of it there's a snake staticshape. The code to create the log is similar with the one in AIPlayer.cs. It's basically calling getTransform from a path marker and sets it to be the log's transform after creating teh log.

The position XForm echo showed that the object is still at the origin (0 0 0). When I echoed it again after the setTransform of the log, it showed that the snake is still near the origin.

EDIT: I've tried calling the setTransform of the log after the player is attached on top of it and it has proven my assumption. The player is not updated according to the new transform and still siting at the last position although it's descending on the Z axis because there's no log below it (gravity anyone?).
#237
06/11/2008 (7:56 pm)
I noticed this behavior as well during some tests, but decided to pursue other things to work on.
due to the way the code works, it simply moves the attached object based on how much it's moved the last frame/tick. so what may work is modifying the settransform method to get a new transform offset for the object and it's child objects. after getting this, it may simply update itself next frame, or you could run the functions that handle that. but i don't remember the names off the top of my head.
#238
06/11/2008 (9:14 pm)
Ok i know i already asked about the difs, but what about polysoup meshes, they are based off of tsstatic which i think comes from shapebase, would it be possible to attach those to vehicles with this resource? Thanks again
#239
06/23/2008 (12:47 am)
Sorry to bump in again. Just wanna ask does the attachChild() method ALWAYS work if the child is non NULL? I mean, I've experienced something peculiar. I am sure that the updateAttachment / ray casting returned true (meaning that there's a platform under the player), but it couldn't attach to it. Now, because the player itself isn't a NULL object, I reckon that there's another factor. But I don't know what that is. Can anyone help me? Thanks a lot in advance.

BTW, here's my onMovableSurface function:
if (%col.getClassName() $= "AIPlayer" && %col.getDatablock().className $= "Platform")
   {
	error("i'm on a Platform! ID:" SPC %col);
       %col.attachchild(%obj);
   }

Now, the console can print the error but the player can't attach itself to the platform and just goes straight down to a never ending pit (didn't add any diff / terrain below so the player would drop for eternity :D ).
#240
06/23/2008 (4:52 am)
if (%col.getClassName() $= [b]"AIPlayer"[/b] && %col.getDatablock().className $= "Platform")

Unless the thing trying to attach is an AIPlayer, that will fail, and you won't attach.