Crossbow lying on floor rather than spinning in mid-air
by Andrew · in Torque Game Engine · 03/24/2006 (5:39 am) · 7 replies
I noticed that the crossbow model will spin in mid-air when inserted into game. This occurs to the other guns that I insert into the game as well. How do I make the gun and ammo lie flat on the ground (for realism)?
#2
03/24/2006 (5:50 am)
Yeah, it would the only problem with that is you can't have the game do that when you toss a weapon. (A weapon object created on-the-fly).
#3
03/24/2006 (5:52 am)
Urm. So how would I go about making this change happen on the fly? Like when the enemies drop their weapons.
#4
You can also set this up in script so everytime you add a new item to your world it automatically flags the 'rotation' & 'static' fields as false.
Eg
The 'weapon' in the function refers to all items with a classname of 'weapon'. Check out the crossbow script and look at the datablock ItemData(crossbow) section. In there you'll notice it defines the classname as 'weapon'.
Eg
This lets you use one function for all items with a classname of 'Weapon' rather than writing a whole heap of functions out.
If you just wanted the function to act upon one specific item you could use...
Hope that makes sense.
03/24/2006 (5:59 am)
C2 is right about the rotation. You must deselect the 'rotation' box in the items properties (Hit F3 with it selected, in mission editor) then save mission and restart. It wont be rotating anymore. To get items to drop to the ground deselect the 'static' checkbox. You can also set this up in script so everytime you add a new item to your world it automatically flags the 'rotation' & 'static' fields as false.
Eg
// Specify values on adding items via mission editor
function Weapon::onAdd(%this,%obj)
{
%obj.rotate=(0); //no rotation on add
%obj.static=(0); //drop to the ground on add
}The 'weapon' in the function refers to all items with a classname of 'weapon'. Check out the crossbow script and look at the datablock ItemData(crossbow) section. In there you'll notice it defines the classname as 'weapon'.
Eg
datablock ItemData(Crossbow)
{
// Mission editor category
category = "Weapon";
// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
[b]className = "Weapon";[/b]
// Basic Item properties
shapeFile = "~/data/shapes/crossbow/weapon.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
// Dynamic properties defined by the scripts
pickUpName = "a crossbow";
image = CrossbowImage;
};This lets you use one function for all items with a classname of 'Weapon' rather than writing a whole heap of functions out.
If you just wanted the function to act upon one specific item you could use...
// Specify values on adding items via mission editor
function Crossbow::onAdd(%this,%obj)
{
%obj.rotate=(0); //no rotation on add
%obj.static=(0); //drop to the ground on add
}Hope that makes sense.
#5
That statement is not correct. If you throw an item, such as a backpack mounted to a node on the player, it will bounce on the ground and come to a stop.
Throwing an item makes a call to item.cs to a function named function ItemData::onThrow(%this,%user,%amount) This is what's used by default unless you specify your own throw function.
Eg
When you throw a weapon, it is throwing an item, NOT a shapeImage.
03/24/2006 (6:03 am)
Quote:
Yeah, it would the only problem with that is you can't have the game do that when you toss a weapon. (A weapon object created on-the-fly).
That statement is not correct. If you throw an item, such as a backpack mounted to a node on the player, it will bounce on the ground and come to a stop.
Throwing an item makes a call to item.cs to a function named function ItemData::onThrow(%this,%user,%amount) This is what's used by default unless you specify your own throw function.
Eg
function BackPack::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);
%user.unmountImage($BackPackSlot);
// 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;
};
MissionGroup.add(%obj);
%obj.schedulePop();
return %obj;
}When you throw a weapon, it is throwing an item, NOT a shapeImage.
#6
03/24/2006 (7:21 am)
Maybe you could have it so that it throws rigid body shapes like they do in HL2 and CSS and then once it comes to a rest it turns itself into a normal shape to conserve energy. Might be a little difficult and I don't know how well it will work.
#7
03/24/2006 (2:34 pm)
Only issue I'm having is making the weapon be at a 90 degree angle (laying down on its side) instead of in a holding position. Is there a way in script to determine the rotation of the weapon in the world? If the model is changed, the mounted image system is also screwed.
Torque Owner Chris Byars
Ion Productions