Author Topic: How to bypass height control? [SOLVED]  (Read 6869 times)

Ok, here goes. First of all, how do I go about using the spacebar for an action while in a vehicle, if that's even possible? Secondly, how do I detect if a physics vehicle is grounded (in other words, wheels on the ground)? Thirdly, would I use applyImpulse to nudge a physics vehicle, or another function pertaining to velocity? Solved, look below for new questions. New issue, spacebar hits conflict with Support_HeightControl.
« Last Edit: July 19, 2014, 04:10:25 PM by BluetoothBoy »

1. Check the ::onTrigger function. There's three arguments, one for the object(or is it datablock?) calling it, one for the slot (i forget the numbers, but one is left click, one is right click, one is jump) and another is true when you press it and false when you release it.

2. Not sure

3. Maybe, you could also use addVelocity

::onTrigger has four arguments, not three. The %datablock of whatever object, the %object, the %trigger that's been pressed or released, and whether it was %pressed or released. Or, as I usually name them, %data, %this, %trig, %tog.

::onTrigger has four arguments, not three. The %datablock of whatever object, the %object, the %trigger that's been pressed or released, and whether it was %pressed or
Ok, I couldn't remember whether it used the datablock, or the object. I didn't think of using both

Or, as I usually name them, %data, %this, %trig, %tog.
%this should be the first argument. The standard comes from the this pointer in C++ (probably other languages too), which is automatically added (similarly to TorqueScript, except instead of being an argument added to the function header, it's just automatically there) to refer to the object the function was called upon. It's been carried to TorqueScript where the standard is to name the first first argument of a method %this. It can be named anything else, obviously, and it doesn't really matter, but to give the name %this to something other than the object the method is called upon, is just.....blech...and it could probably confuse people who are used to other languages and don't carefully pay attention to your variable naming convention

%this should be the first argument. The standard comes from the this pointer in C++ (probably other languages too), which is automatically added (similarly to TorqueScript, except instead of being an argument added to the function header, it's just automatically there) to refer to the object the function was called upon. It's been carried to TorqueScript where the standard is to name the first first argument of a method %this. It can be named anything else, obviously, and it doesn't really matter, but to give the name %this to something other than the object the method is called upon, is just.....blech...and it could probably confuse people who are used to other languages and don't carefully pay attention to your variable naming convention
I think using %this is a bad idea because it's horribly undescriptive.

I think using %this is a bad idea because it's horribly undescriptive.
true, however if you're reading the function and you see "%this" you should think of the object that it's being called on.. depends if you're into convention or not

I think using %this is a bad idea because it's horribly undescriptive.
It's perfectly descriptive to me, did you not read half the post?

Secondly, how do I detect if a physics vehicle is grounded (in other words, wheels on the ground)?

Thirdly, would I use applyImpulse to nudge a physics vehicle, or another function pertaining to velocity?

To detect if a physics vehicle is on the ground you're going to want to see how tall the world box is, divide it by 2, and shoot a raycast down that's a little bit longer than that length.

Something like this:

Code: [Select]
function vehicleOnGround(%vehicle) {
    %wbox = %vehicle.getWorldBox();
    %zSize = mAbs(getWord(%wbox, 5) - getWord(%wbox, 2));
    %downVector = vectorScale(%vehicle.getUpVector(), -1);
    %ray = containerRayCast(%vehicle.getWordBoxCenter(), vectorAdd(%vehicle.getWorldBoxCenter(), vectorScale(%downVector, (%zSize/2)*1.1)), $TypeMasks::All, %vehicle);
    return isObject(%ray);
}

Then, to nudge a vehicle, use %vehicle.setVelocity(vectorAdd(%vehicle.getVelocity(), %nudgeVelocity));

Thanks $trinick, I just discovered how to do all that before seeing your post.

Anyway, two new questions. I have everything I asked about working just fine, but I now have a new issue. First of all, since I am calling Armor::onTrigger, the activate animation no longer plays. Should I fix this simply by adding:
Code: [Select]
if(%key $= 0)
{
     %player.playThread(2, activate);
}
...or is there a better way to fix it?

Secondly, onTrigger won't detect spacebar presses when the player is mounted to the physics vehicle I need them mounted to. It returns 2 just fine unmounted, but nothing is returned for a spacebar press when mounted.

Code:
Code: [Select]
package Jump
{
function Armor::onTrigger(%obj, %player, %key)
{
echo(%key);
//Parent.
Parent::onTrigger(%obj, %player, %key);
//Are we mounted?
if(%player.isMounted())
{
%mountedVehicleName = %player.getObjectMount().getDataBlock().getName();
%mountedVehicle = %player.getObjectMount();
//Check to see if we hit the jump key.
if(%key $= 2)
{

//We did, check to see if we're mounted to a board.
if(%mountedVehicleName $= "snowboardingVehicleBlack" || %mountedVehicleName $= "snowboardingVehicleWhite")
{
//Check to see if we're grounded; can't jump in the air!
%vector = %player.getForwardVector(); 
%mask = $TypeMasks::TerrainObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::StaticObjectType | $TypeMasks::FxBrickObjectType | $TypeMasks::CorpseObjectType | $TypeMasks::PlayerObjectType; 
%feetPos = posFromTransform(%mountedVehicle.getTransform()); 
%feetEnd = getWord(%feetPos , 0) @ " " @ getWord(%feetPos , 1)@ " " @ getWord(%feetPos , 2) - 0.5 @ " 1 0 0 0"; 

if(containerRayCast(%feetPos, %feetEnd, %mask, %mountedVehicle))
{
//We are, apply impulse for jump.
%mountedVehicle.applyImpulse(%mountedVehicle.getTransform(), "0 0 700");
}
}
}
}
}
};
activatePackage(Jump);

Thanks $trinick, I just discovered how to do all that before seeing your post.

Anyway, two new questions. I have everything I asked about working just fine, but I now have a new issue. First of all, since I am calling Armor::onTrigger, the activate animation no longer plays. Should I fix this simply by adding:
Code: [Select]
if(%key $= 0)
{
     %player.playThread(2, activate);
}
Im not sure on the data type of %key but it looks like you are comparing a string to an int. I believe they both get the same result but I would use %key == 0 or %key $= "".

Im not sure on the data type of %key but it looks like you are comparing a string to an int. I believe they both get the same result but I would use %key == 0 or %key $= "".
The proper way is == for numerical values and $= for strings and stuff.

First of all, since I am calling Armor::onTrigger, the activate animation no longer plays. Should I fix this simply by adding:
Code: [Select]
if(%key $= 0)
{
     %player.playThread(2, activate);
}
...or is there a better way to fix it?
For the first problem, refer to Xalo's post.
::onTrigger has four arguments, not three. The %datablock of whatever object, the %object, the %trigger that's been pressed or released, and whether it was %pressed or released. Or, as I usually name them, %data, %this, %trig, %tog.
Secondly, onTrigger won't detect spacebar presses when the player is mounted to the physics vehicle I need them mounted to. It returns 2 just fine unmounted, but nothing is returned for a spacebar press when mounted.

Code:
Code: [Select]
package Jump
{
function Armor::onTrigger(%obj, %player, %key)
{
echo(%key);
//Parent.
Parent::onTrigger(%obj, %player, %key);
//Are we mounted?
if(%player.isMounted())
{
%mountedVehicleName = %player.getObjectMount().getDataBlock().getName();
%mountedVehicle = %player.getObjectMount();
//Check to see if we hit the jump key.
if(%key $= 2)
{

//We did, check to see if we're mounted to a board.
if(%mountedVehicleName $= "snowboardingVehicleBlack" || %mountedVehicleName $= "snowboardingVehicleWhite")
{
//Check to see if we're grounded; can't jump in the air!
%vector = %player.getForwardVector(); 
%mask = $TypeMasks::TerrainObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::StaticObjectType | $TypeMasks::FxBrickObjectType | $TypeMasks::CorpseObjectType | $TypeMasks::PlayerObjectType; 
%feetPos = posFromTransform(%mountedVehicle.getTransform()); 
%feetEnd = getWord(%feetPos , 0) @ " " @ getWord(%feetPos , 1)@ " " @ getWord(%feetPos , 2) - 0.5 @ " 1 0 0 0"; 

if(containerRayCast(%feetPos, %feetEnd, %mask, %mountedVehicle))
{
//We are, apply impulse for jump.
%mountedVehicle.applyImpulse(%mountedVehicle.getTransform(), "0 0 700");
}
}
}
}
}
};
activatePackage(Jump);
For the second problem, it may be a different class that's calling ::onTrigger when you're in a vehicle. Like WheeledVehicleData or something. Try using trace(1); when you push the space bar in the vehicle.

I remember an old convertible vehicle that had an animation when you hit the spacebar. I long sense lost it however, if someone else has it then it should be a good reference.

The proper way is == for numerical values and $= for strings and stuff.
Oops, forgot about that, my bad.
For the first problem, refer to Xalo's post.For the second problem, it may be a different class that's calling ::onTrigger when you're in a vehicle. Like WheeledVehicleData or something. Try using trace(1); when you push the space bar in the vehicle.
I don't understand what you mean for the first one; I already knew all that, I just didn't think I needed the last argument, so I left it out. Are you suggesting I use the last arg in some way, or is it simply that parenting that argument will fix it?

I don't understand what you mean for the first one; I already knew all that, I just didn't think I needed the last argument, so I left it out. Are you suggesting I use the last arg in some way, or is it simply that parenting that argument will fix it?
By not parenting the last argument, you are breaking some features that use Armor::onTrigger. You should also use the last argument, or else all this will be called when they push space, and again when it's released.