Jump to content

Some Mounting Questions


flysouth

Recommended Posts

I am trying to figure out what kinds of things can mount to what.

I have mounted ShapeBaseImageData to a vehicle without a problem.


What if I wanted to create something like a train where I had many coaches that the player could choose from at run time.

I have not figured out what object type allows for connecting to the same type.

So in the train example the motor coach would be a vehicle. The next coach could be a ShapeBaseImageData object but

then how do you connect the next coach, because as far as I worked out you cannot mount ShapeBaseImageData to abother ShapeBaseImageData.


How would I go about connecting them all? :cry:


Just to add... I dont want to make a train, thats just an example. What I would like to do is allow the player to build up obejects sort of like using lego.

The main question is what objects in T3D allow more of the same type to me mounted / attached to them?

Link to comment
Share on other sites

The first thing, is I'd point out that ShapeBaseImage is primarily intended for use as mounted weapons.


If you were trying to mount "real" objects, such that may have collisions or the like, you'd want to use a different class, such as ShapeBase, or the like.


So for example, you have here:

https://github.com/GarageGames/Torque3D/blob/7bba3ee2de610c2757bc70eba10db869bab72a85/Templates/Full/game/scripts/server/vehicle.cs#L98


Which mounts the player to the vehicle at a given node slot.


For your traincars, you'd Shapebase or the like for your cars, and mount them like the above call. Then as needed set their mountPos and mountRot fields to tweak their position(assuming you don't have a special node to mount them to specifically). These are added to the parent's transform.


This way, when your vehicle moves, they will move with it.

Link to comment
Share on other sites

Thanks for the suggestions.


I have experimented with player mounting, weapon mounting and trurret mounting to vehicles.

The turret mounting seems to be broken - it mounts but is out of sync with the vehicle and I could not get it to do anything.

I also tested the image mounting which too works fine but is not what I am looking for.


Yes I am looking to mount real objects such that they may have collisions. Some of them will have to be mounted on vehicles.


I will do some tests based on the information above and post my findings or questions here later.

Link to comment
Share on other sites

Okay I tried the following and it gave no errors but even though it shows that it is mounted to the vehicle, there is nothing visble on the vehicle.

I just used a healthkit datablock

datablock ItemData(Botx1)
{
  category = "misc";
mountPoint = 0;
  className = "Botx1";
  shapeFile = "art/shapes/BotStuff/botx1.DAE";
  mass = 2;
  friction = 1;
  elasticity = 0.3;
  emap = true;
  pickupName = "a small thing";
  repairAmount = 50;
};

 

I then tried mounting it with the following code:

function Bot1::onAdd(%this, %obj)
{
  Parent::onAdd(%this, %obj)

 ...

  %obj.Btx1 = new Item()
 {  
     dataBlock = Botx1;  
};
 %obj.mountObject(%obj.Btx1, %this.SlotFront);	
}

 

Any ideas what I am doing wrong?

Link to comment
Share on other sites

Thanks Azaezel.

I am trying to do this without modding the c++.

I changed my above code to use a StaticShapeData object and I see it suffers with the same problem as the Turret. It does not stay in sync with the moving vehicle.

This is so frustrating. What do people do with this engine?? Wait let me guess.... the change the c++ to make it work :(

@JeffR - does version 4 sort this stuff out or does it just continue with more of the same?

Link to comment
Share on other sites

This is so frustrating. What do people do with this engine?? Wait let me guess.... the change the c++ to make it work :(

@JeffR - does version 4 sort this stuff out or does it just continue with more of the same?

Bit of a catch 22 there. Engines in a state where folks gotta be wiling and able to throw source mods over so they don't have to touch that area anymore (unless of course it's one of those things that does need tight performance). Fewer folks willing to pitch in on that front, longer it takes.

Link to comment
Share on other sites

Thanks Azaezel.

I am trying to do this without modding the c++.

I changed my above code to use a StaticShapeData object and I see it suffers with the same problem as the Turret. It does not stay in sync with the moving vehicle.

This is so frustrating. What do people do with this engine?? Wait let me guess.... the change the c++ to make it work :(

@JeffR - does version 4 sort this stuff out or does it just continue with more of the same?

 

Yeah, the entities are being intended to be very flexible, especially with the mounting. I'll have a look at the static shape mounting bit, it's not as flexible as it should be, but it definitely should at least keep up with the mount object. It sounds like the interpolation isn't handling it correctly as is, which means it's likely a bug.


With 4.0, the general ethos is going to be more of a "You shouldn't have to use the source unless you're optimizing for performance, or crazy specialized stuff, but general gameplay shouldn't require source changes. Source is there to make things shiney and fancy, not to get the game running".

Link to comment
Share on other sites

Fewer folks willing to pitch in on that front, longer it takes.

It would be easier to get involved if there was some sort of class diagram so that one could get a better idea of how all the bits fit together.

What I find strange is that many of these fixes have already been done by various people years ago but the fixes have never been put into the 'official' release.

It seems almost that some of these things are being fixed again and again by different people :shock:

Link to comment
Share on other sites

Yeah, used to be a largeish library of resources on the legacy forums back when it was a paid product. Unfortunately, quite a few went 404. So.


Speaking of not wanting to have to touch source: few mounting related script utils:


animated mount chain animation linking (everything in the iterative mount chain plays the same animation simultaneously):

function smartPlayThread(%obj,%anim,%direction)
{
if (!isObject(%obj)) return;
%obj.inTransition = true;
if (%direction)
{
	%obj.stopThread(0);
	%obj.playThread( 0,%anim );
	%obj.setThreadDir(0,true);
}
else
{
	//play deployment backwards
	%obj.stopThread(0);
	%obj.playThread( 0, %anim );
	%obj.setThreadPosition(0,1);
	%obj.setThreadDir(0,false);
}

%count = %obj.getMountedObjectCount();
for (%i=0; %i<%count; %i++)
{
	smartPlayThread(%obj.getMountedObject(%i),%anim,%direction);
}
}

 

root mount chain finding


function findRootObject(%obj)
{	if (!isObject(%obj)) return -1;
   %ret = %obj;
   if (isObject(%obj.getObjectMount()))
	%ret = findRootObject(%obj.getObjectMount());
return %ret;
}

full chain cleanup:


function killMountchain(%obj)
{	
if (!isObject(%obj)) return;
%count = %obj.getMountedObjectCount();
for (%i=0; %i<%count; %i++)
{
	if (isObject(%obj.getMountedObject(%i)))
		killMountchain(%obj.getMountedObject(%i));
}
%obj.schedule(0,"delete");
}

all parts damaged evenly:


function setMountChainDamage(%obj,%damagePercent)
{	
if (!isObject(%obj)) return;
%count = %obj.getMountedObjectCount();
for (%i=0; %i<%count; %i++)
{
	if (isObject(%obj.getMountedObject(%i)))
		setMountChainDamage(%obj.getMountedObject(%i),%damagePercent);
}

%obj.setDamageLevel(%obj.getMaxDamage()*%damagePercent);
}

 

Do note these'll likely be considered legacy come 4.0 specs.

Link to comment
Share on other sites

function ProjectileData::onCollision(%this,%obj,%col,%fade,%pos,%normal,%hitbox)
{
if((!isObject(%obj))||(!isObject(%col))) return;
  if (%col == %obj.sourceObject) return;
//echo("ProjectileData::onCollision("@%data.getName()@", "@%proj@", "@%col.getClassName()@", "@%fade@", "@%pos@", "@%normal@", "@%hitbox@")");	
if ((%col.dataBlock.category $= "RigidShape")||(%col.dataBlock.category $="Turrets"))
{
	if (%obj.sourceObject.dataBlock.category $= "bots")	%col.lastDamager = %obj.sourceObject;
}

if (findRootObject(%col).team == %obj.team)
{
	if (%obj.getDataBlock().heals)
		%damage = -%this.directDamage;
}
else
	%damage = %this.directDamage;
...more game specific stuffs...
}

for one example


function ShapeBaseData::damage(%this, %obj, %source, %position, %amount, %damageType)
{
  // Ignore damage by default. This empty method is here to
  // avoid console warnings.
  %damagePercent = %obj.getDamagePercent();
  setMountChainDamage(%obj,%damagePercent);
}

for another

animation one should be self-evident.

edit: and yeah, had forgotten about that fork...

Link to comment
Share on other sites

  • 2 weeks later...

Not sure about intercepting, but an example would be like, suppose you had a weapon with a bunch of mounted attachments that you want to do something when you reload(have little dodads move, etc)


So each of those would have a "reload" animation. Then you'd use the smartPlayThread(%myGun,"reload",true); to tell the gun to play the reload animation, but it would also iterate over all the mounted objects and tell them to play their reload animations as well.


This would let you have all your attachments do their little dodad animations upon the gun being reloaded, as per the example.


Hopefully that explains the idea. If not, is there a particular scenario you're thinking of?

Link to comment
Share on other sites

Thank for the explanation JeffR.

I wish to create a 'vehicle' with various bits that attach as the game proceeds. Some of the bits need to be animated, but hopefully they are more than just an image ie. they can detect collisions etc.

I have tried various things but apart from images everything else seems to have an issue staying in sync with the vehicle when it moves.

For various reasons I dont really want to mod the C++ to get this working. I am currently busy with the artwork and am hoping ver 4 comes out soon and fixes some of my problems :lol:

Link to comment
Share on other sites

I merged in some improvements to the mounting a week or two back, so if Johzx's binaries are up to date, it should include those improvements.


You'll still see some jittery behavior if you have a chain of mounted objects, like a scope mounted onto a gun mounted onto a vehicle, and when the vehicle moves, the scope'll lag behind some, but the improvements helped with at least the first-step mounted objects to keep up better(and allow most classes to do it, even the TSStatics).


So I'd say check with Johzx on if his precompiled binary is up-to-date and give it a whirl with the mounting improvements in there and lemme know if that helps.

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...