Game Development Community

Standardized character TSShape interaction

by Jonas · in Torque 3D Professional · 10/21/2013 (6:08 pm) · 2 replies

Hello everyone

I am trying to find a good way, through script, to make a standardized way of dealing with TSShape interactions with the player.

Example: In the the game world there are trees that dot the landscape. The player should be able to interact with these trees by chopping them down. Depending on the level of the tool used to do that the process of doing so should take different amount of time(Like characters can have varying HP)

I am however unaware of how i would go about doing this with a non-character object in T3D and as the process would be used on a macro scale it is not possible to use triggers and such to determine via variable check what object should have its HP decreased.

The currently theory i have is to use the "bulletImpact" to determine what object needs its HP decreased, from there pass along the Object ID and HP status to the server database. When any given ObjectID reaches zero command is sent to play "Fall" animation and so on.

So, to summarize this is what i am having difficulty with:

1. unsure of how i would go about detecting what the "bullet" impacts with, in terms of Object ID.

2. Determining what type of object is being hit is also vital, i need to be able to check if the Object is of the right type(Tree), how do i go about reading a Dynamic field from a Object if i know the ID.

Any help or suggestions at all are greatly appreciated.

Best regards
Jonas

About the author

Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.


#1
10/22/2013 (6:14 am)
1. On a collision callback via the colliding object (or raycast). Remember IDs can change when loading levels so you'd want to use permenant IDs or names. Getting the ID of the object is easy - for a bullet it's automatic (look in projectile.cs), for a raycast it's the first word returned.

2. Look in the script CHM file for getField, getDynamicField, getFieldValue, etc. It's how you should access fields/dynamicFields.

Ideally you might want to create a new class of object (based off an existing one), then you'd check for the %collision.getClassName(), get the ID, alter the HP and make an update call to alter the state (eg: model, collision, etc)
#2
10/22/2013 (9:10 am)
Keep in mind that TSStatics are a light weight class not meant for "interaction", but using a StaticShape you can take advantage of built callbacks, shapebase damage handling, etc.