Game Development Community

Telekinesis

by Chip Lambert · in Torque Game Engine · 06/30/2004 (9:24 am) · 3 replies

Hello all

In one of the projects I'm working on, one of my designers is wanting to implement telekinesis as a special ability. What is the best way to implement this feature? It would be the ability to hit enemies with rocks (small), push people down (like Star Wars Force Push), and the such. Any ideas you guys have would be appreciated.

Thanks!

Chip

#1
07/12/2004 (10:45 am)
You would probably do something like the object selection resource and then once you know the object, do an applyImpulse(). Something like that anyways...

-s
#2
07/29/2004 (4:31 pm)
You would need to find an object, I would get raycasting would be good for that but a bit expensive. Than once you find that object you can do what you like. If you do use applyImpule() as Stephen mentioned besure the object you control is based from the shapebase class or one of it's sub class. that function does not work for static shapes for instance.
#3
07/02/2009 (3:28 pm)
@Chip

This is some of the code I have recently put together for the same thing you are trying to implement.

First you need to have a function that will perform a RayCast:

function Check::Eye_Distance_HandleRay(%player, %distance, %typeMasks)
		{
echo("**************Commencing Eye_Distance_HandleRay**************");
echo("--------------------Checking For Objects--------------------");
			%eye = %player.getEyeVector();
			%vec = vectorScale(%eye, %distance);
			%start = %player.getEyeTransform();
			%end = VectorAdd(%start, %vec);
echo("Eye Vec: "@ %eye); // Remove this Line When Script is Complete
echo("Vec Scl: "@ %vec); // Remove this Line When Script is Complete
echo("Vec Str: "@ %start); // Remove this Line When Script is Complete
echo("Vec End: "@ %end); // Remove this Line When Script is Complete
			%found = ContainerRayCast (%start, %end, %typeMasks, %player);
			if(%found)  
				{ 
				echo("======Raycast has found an Object within the Specified TypeMask.======");
				//Parse out the Found Object's ID Handle
				%handle = getWord(%found, 0);
				echo("Object has been found. ID: "@ %handle); // Remove this Line When Script is Complete
return %handle;
				}
			else
				{
echo("======Raycast did not encounter any Object within the Specified TypeMask.======");
				}		
echo("--------------------Raycast Complete--------------------");
}

This will fire a ray from the player's eye out to a certain predefined distance until it reaches its limit or until an object of specified TypeMask has been encountered. It will then parse out the handle of the object encountered and Return the Handle.

Then you need to use another function to apply the pushback:

// This Function applies the physical force to the object.
	// %this  = Object ID
	// %vec   = Vector Force is to Follow
	// %force = Ammount of Force Applied
	function PushBack(%this, %vec, %force)
	{
		%objectMass = %this.getDatablock().mass;
		echo("Object's Mass:"@ %objectMass);
		echo("Eye Vector:"@ %vec);
		echo("Force Applied:"@ %force);
		%impulseVector = vectorScale(%vec, %objectMass * %force);
		
		%this.applyImpulse( %this.getWorldBoxCenter(), %impulseVector);
	}

%vec can simply be the players eye vector:

%player.getEyeVector();

So to call the code:

function serverCmdForcePush(%client)
{
%player = %client.player;
%handle = Eye_Distance_HandleRay(%player, %distance, PlayerObjectType);
PushBack(%handle, %client.player.getEyeVector(), %force);
}

Where %distance and %force are amounts you specify.
If you run this as a serverCmd the client handle will be passed trough and allow you to then grab the handle of the player. But if you attach this to a ShapeImage, like a weapon, some alterations will need to be made.

Then finally just bind the serverCmdForcePush to a hotkey in the actionmap.

Place this in default.bind.cs
moveMap.bindCmd(keyboard, "q", "commandToServer('ForcePush');", "");

Hope this was helpful.