Game help: moving/destroying Other objects during a game.
by Mo Touman · in General Discussion · 03/12/2004 (3:20 am) · 4 replies
All,
I am trying to use the tutorials to create a very simple game. They have been very useful in creating the world and the objects in the world.
The next stage I want, I have not been able to find an example, which I hope someone can help me with (maybe it would just be, pointing me at the right tutorial)
What I want to do is: When I touch one object (A) I want a different object (B) to move or be destroyed. (I have been able to use the tutorials to describe triggering & the onCollision static shape event)
How do I do this? Am I using the correct approach?
Where I think I am having difficulty is:
1. What type of shape should object B be in the world editor? a Static shape? I want to either move or destroy it when object A is touched.
Is there a list of the methods that I can call on Object B from Object A.
2. I don't know how to keep an identifier/reference for object B, within the oncollision event for A, I therefore cannot call any object B methods
3. How do I move or destory the object in the world?
Many thanks in advance.
I am trying to use the tutorials to create a very simple game. They have been very useful in creating the world and the objects in the world.
The next stage I want, I have not been able to find an example, which I hope someone can help me with (maybe it would just be, pointing me at the right tutorial)
What I want to do is: When I touch one object (A) I want a different object (B) to move or be destroyed. (I have been able to use the tutorials to describe triggering & the onCollision static shape event)
How do I do this? Am I using the correct approach?
Where I think I am having difficulty is:
1. What type of shape should object B be in the world editor? a Static shape? I want to either move or destroy it when object A is touched.
Is there a list of the methods that I can call on Object B from Object A.
2. I don't know how to keep an identifier/reference for object B, within the oncollision event for A, I therefore cannot call any object B methods
3. How do I move or destory the object in the world?
Many thanks in advance.
#2
Many Thanks for that - It is very helpful.
I do have a follow up question regarding this. Basically I want a "rock" to move when the player moves over a "box".
(I have created the "rock" (object A) (and box, object B) using ItemData::create in a .cs script in the server/scripts directory.)
Could you give me an example of the setTransform call please (parameters). In particular how do I refer to the rock object from within the onCollision method of the box object?
Many thnaks again.
03/22/2004 (1:31 am)
Thomas,Many Thanks for that - It is very helpful.
I do have a follow up question regarding this. Basically I want a "rock" to move when the player moves over a "box".
(I have created the "rock" (object A) (and box, object B) using ItemData::create in a .cs script in the server/scripts directory.)
Could you give me an example of the setTransform call please (parameters). In particular how do I refer to the rock object from within the onCollision method of the box object?
Many thnaks again.
#3
I'd just do a bounding box collision around your mans hands and when that intersects another scenery object, call some custom code. This may be specified in a script but to keep things simple you might want to hard-code some common behaviours.
As to moving it or destroying it, that depends on what you've got available in your engine/library. Usually you'd just translate its transform matrix to move it, or set some flags on the object to indicate "dont render" and "dont collide". Maybe you can just free it - the choice is yours.
03/22/2004 (9:13 am)
I think this depends a lot on what functionality you've coded into your world editor, and how you handle accessories/furniture.I'd just do a bounding box collision around your mans hands and when that intersects another scenery object, call some custom code. This may be specified in a script but to keep things simple you might want to hard-code some common behaviours.
As to moving it or destroying it, that depends on what you've got available in your engine/library. Usually you'd just translate its transform matrix to move it, or set some flags on the object to indicate "dont render" and "dont collide". Maybe you can just free it - the choice is yours.
#4
03/26/2004 (9:52 am)
Mo, if you care to share this with the community, write up a resource of this, include some code and post it to the resources - sounds real good.
Torque Owner Thomas \"Man of Ice\" Lund
Short explaination of what I do. This is all from memory without access to my code (@work at the moment)
On mission start I dynamically create a new simgroup on the server and then dynamically add objects created with "%object = new Item() {DataBlock = Chest);"
I add these new objects to the simgroup. When the server resets the map and/or stops the mission I delete the simgroup, and hence all the dynamically created objects.
The code I've used to cut'n'paste this together is based in the fps.starter. Try to look at how the AIPlayer is created that runs around ingame. I think its the spawn() function that I took the create code from and modified.
No matter what you do, please remember to delete your dynamically created objects or the server might crash.
The items I spawn are Item objects that I extend into my own datablocks (in my case treasure chests in a Chest datablock), but could be anything.
Once created you got access to them on the same basis as if they had been created with the mission editor.
Movement of the objects are done with the setTransform() method. You could e.g. get the worldbox position of a spawnsphere, and the use its position to feed into the setTransform() to move the object instantaniously to that point.
Hope that helps you in the right direction