Item position on drop
by Norris Bonner · in Torque Game Engine · 07/01/2006 (1:18 pm) · 3 replies
Ok, I finally got most of the code working that I have been tinkering with.
I have an AI player drop an item and when the player pics up the item it increments the score and displays it on the screen (still have to fix the portion where the player drops the item (working on it)) When the item is thrown by the AI, it rotates like I want it to but it sits on the ground. I've looked on the forums and couldnt find the answer. How do I get a new item that just dropped to float in the air and not just drop to the ground? Right now my item onthrow code is as follows:
function ItemData::onThrow(%this,%user,%amount)
{
// Remove the object from the inventory
if (%amount $= "")
%amount = 1;
if (%this.maxInventory !$= "")
if (%amount > %this.maxInventory)
%amount = %this.maxInventory;
if (!%amount)
return 0;
%user.decInventory(%this,%amount);
// Construct the actual object in the world, and add it to
// the mission group so it's cleaned up when the mission is
// done. The object is given a random z rotation.
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
count = %amount;
rotate = "1"; //rotate thrown item
mass = 5; //stop item from flying all over the place when thrown
friction = 2;
elasticity = 0.3;
};
MissionGroup.add(%obj);
%obj.schedulePop();
return %obj;
I have an AI player drop an item and when the player pics up the item it increments the score and displays it on the screen (still have to fix the portion where the player drops the item (working on it)) When the item is thrown by the AI, it rotates like I want it to but it sits on the ground. I've looked on the forums and couldnt find the answer. How do I get a new item that just dropped to float in the air and not just drop to the ground? Right now my item onthrow code is as follows:
function ItemData::onThrow(%this,%user,%amount)
{
// Remove the object from the inventory
if (%amount $= "")
%amount = 1;
if (%this.maxInventory !$= "")
if (%amount > %this.maxInventory)
%amount = %this.maxInventory;
if (!%amount)
return 0;
%user.decInventory(%this,%amount);
// Construct the actual object in the world, and add it to
// the mission group so it's cleaned up when the mission is
// done. The object is given a random z rotation.
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
count = %amount;
rotate = "1"; //rotate thrown item
mass = 5; //stop item from flying all over the place when thrown
friction = 2;
elasticity = 0.3;
};
MissionGroup.add(%obj);
%obj.schedulePop();
return %obj;
About the author
Torque Owner Norris Bonner
if (%obj.isbot == true)
{
%obj.throw(SoulItem);
}
Still need help with getting the position of the dropped object and placing it higher off the ground on the z axis.