Thrown item colliding with terrain
by rpi (#0011) · in Torque Game Engine · 03/16/2005 (5:42 pm) · 10 replies
Alright, so in my game, there are items on the ground that a player can pickup and throw. Right now, if you throw an item at another player, they just pick it up. I want to change it so when the item is in-flight, it will do something to a player when they collide.
So, in my ItemData::onThrow function, when I create a new object, I also give it another parameter, thrown, that is set to one:
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
count = %amount;
thrown = 1;
};
Next, in ItemData::onPickup, I check if the object was thrown, in which case, the function returns 0, not picking up the item. Otherwise, the item is picked up as normal.
Now, this seems to work, with a thrown object not being picked up. Hoever, I'd like thrown items to be able to be picked up again after they've landed, and finished bouncing around. This means toggling thrown back to 0, but I'm not really sure where this needs to be done.
Any help would be greatly appreciated.
So, in my ItemData::onThrow function, when I create a new object, I also give it another parameter, thrown, that is set to one:
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
count = %amount;
thrown = 1;
};
Next, in ItemData::onPickup, I check if the object was thrown, in which case, the function returns 0, not picking up the item. Otherwise, the item is picked up as normal.
Now, this seems to work, with a thrown object not being picked up. Hoever, I'd like thrown items to be able to be picked up again after they've landed, and finished bouncing around. This means toggling thrown back to 0, but I'm not really sure where this needs to be done.
Any help would be greatly appreciated.
#2
I'm fairly new to Torque so I'm not sure if what I'm about to suggest is possible, but how about in the Items onCollision function check, using masks, to see if it has collided with Terrain or Interior object types, if so, set Thrown to 0?
Regards,
Harley.
03/19/2005 (3:26 am)
Hi,I'm fairly new to Torque so I'm not sure if what I'm about to suggest is possible, but how about in the Items onCollision function check, using masks, to see if it has collided with Terrain or Interior object types, if so, set Thrown to 0?
Regards,
Harley.
#3
03/19/2005 (3:05 pm)
Another sugestion... how about checking the velocity of the object?
#4
In the meantime though, I'll probably go with the scheduling thing as a workaround.
03/21/2005 (4:07 pm)
I like the idea of checking the velocity. How would I go about checking that though? There is a function GameBase::getVelocity(), but the return type is Point3F. I'm not quite sure what that is, or how one handles it in torquescript.In the meantime though, I'll probably go with the scheduling thing as a workaround.
#5
03/21/2005 (5:21 pm)
Yeh Mathieu's idea is better. I'm pretty sure Item has a getVelocity function that you can call through script.
#6
03/21/2005 (5:30 pm)
%velMagnitude = VectorLen(%obj.getVelocity());
#7
abduction/server/scripts/item.cs (108) Unkown command getVelocity
Object Chicken(47) Chicken -> Animal -> ItemData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
I think its because the Chicken (thrown object) is an ItemData datablock. It seems that GameBase has an implementation of getVelocity, but I'm not sure if I'll be able to switch the datablock type without breaking things.
03/21/2005 (7:37 pm)
With %velMagnitude = VectorLen(%obj.getVelocity()); I get the error:abduction/server/scripts/item.cs (108) Unkown command getVelocity
Object Chicken(47) Chicken -> Animal -> ItemData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
I think its because the Chicken (thrown object) is an ItemData datablock. It seems that GameBase has an implementation of getVelocity, but I'm not sure if I'll be able to switch the datablock type without breaking things.
#8
03/21/2005 (7:45 pm)
Are you able to show the whole function code?
#9
function ItemData::onPickup(%this,%obj,%user,%amount)
{
%itemName = %this.getName();
%velMagnitude = VectorLen(%this.getVelocity());
if (%velMagnitute != 0) {
// call a function to do something as a result of being hit by a thrown object
//
return 0;
}
// after this handles the inventory stuff
}
03/22/2005 (12:35 pm)
I can, but most of it isn't relavant.function ItemData::onPickup(%this,%obj,%user,%amount)
{
%itemName = %this.getName();
%velMagnitude = VectorLen(%this.getVelocity());
if (%velMagnitute != 0) {
// call a function to do something as a result of being hit by a thrown object
//
return 0;
}
// after this handles the inventory stuff
}
#10
Harley.
03/22/2005 (2:07 pm)
I think it should be %obj.getVelocity() rather than %this.getVelocity(). %this refers to the datablock I believe, where %obj is the object (if that makes sense? Just let me know if you need more explanation). Hope this helps.Harley.
Torque Owner Clint S. Brewer
set the schedule when it is thrown
not sure if the syntax is exactly correct but something like:
%obj.schedule(2000, "SetPickupable", 0);
and then have a SetPickupable function for Item
function Item::SetPickupable(%this, val)
{
%this.thrown = %val;
}