Object Selection / Mouse clicking in torque
by Erlend Salbu · in Torque 3D Beginner · 09/29/2009 (2:43 pm) · 5 replies
Im very new to torque and been looking trough the forums for a way to select an object with the mouse and register it but no luck so far since the sollutions iv found have been outdated and for older versions of torque and im too new to it to be able to implement them. from what iv read TGEA have no native scripting support for this, so im wondering if Torque 3d will have native scripting support for selecting an object with a mouseclick, maybe outline it in some fashion etc?
About the author
Recent Threads
#2
09/29/2009 (6:06 pm)
There are two solutions for this in Torque 3D. Both of which require a Torque 3D license. If you have that, they are in the private forum area where I have talked about it.
#3
I am asking because selection features are very essential for my RTS project and I am waiting for a student version of T3D which does not include the source code.
11/11/2009 (5:54 pm)
Can't we do the object selection with mouse click (or drawing a selection marquee, like in the world editor mode) without the source code?I am asking because selection features are very essential for my RTS project and I am waiting for a student version of T3D which does not include the source code.
#4
function PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// Only care about players this time
%searchMasks = $TypeMasks::PlayerObjectType;
// Search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// Get our player/actor
%ai = LocalClientConnection.player;
// If an enemy AI object was found in the scan
if( %scanTarg )
{
// Get the enemy ID
%target = firstWord(%scanTarg);
// Don't shoot at yourself
// if( %target != %ai )
// {
// // Cause our AI object to aim at the target
// // offset (0, 0, 1) so you don't aim at the target's feet
// %ai.setAimObject(%target, "0 0 1");
//
// // Tell our AI object to fire its weapon
// %ai.schedule(100, "setImageTrigger", 0, 1);
// %ai.schedule(150, "setImageTrigger", 0, 0);
// return;
// }
LocalClientConnection.player = %target;
}
// If no valid target was found, or left mouse
// clicked again on terrain, stop firing and aiming
//%ai.setAimObject(0);
%ai.setImageTrigger(0, 0);
}
So you will not fire on selected unit, but select him.
Change variable target to something more fit for this case.
I do not know, is it correct way - LocalClientConnection.player = %target; but it works in single mode. I suppose it will not work in multiplayer.
I hope it helps.
11/14/2009 (10:32 am)
Finish RTS prototype tutorial or just copy art and scripts and change method in PlayGui.cs to such onefunction PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
%ray = VectorScale(%ray, 1000);
%end = VectorAdd(%start, %ray);
// Only care about players this time
%searchMasks = $TypeMasks::PlayerObjectType;
// Search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// Get our player/actor
%ai = LocalClientConnection.player;
// If an enemy AI object was found in the scan
if( %scanTarg )
{
// Get the enemy ID
%target = firstWord(%scanTarg);
// Don't shoot at yourself
// if( %target != %ai )
// {
// // Cause our AI object to aim at the target
// // offset (0, 0, 1) so you don't aim at the target's feet
// %ai.setAimObject(%target, "0 0 1");
//
// // Tell our AI object to fire its weapon
// %ai.schedule(100, "setImageTrigger", 0, 1);
// %ai.schedule(150, "setImageTrigger", 0, 0);
// return;
// }
LocalClientConnection.player = %target;
}
// If no valid target was found, or left mouse
// clicked again on terrain, stop firing and aiming
//%ai.setAimObject(0);
%ai.setImageTrigger(0, 0);
}
So you will not fire on selected unit, but select him.
Change variable target to something more fit for this case.
I do not know, is it correct way - LocalClientConnection.player = %target; but it works in single mode. I suppose it will not work in multiplayer.
I hope it helps.
#5
BTW, RTS Prototype tutorial is great.
11/14/2009 (2:38 pm)
Thanks Zealander, I will try this right now.BTW, RTS Prototype tutorial is great.
Torque 3D Owner Ted Southard