Author Topic: Artificial Jump  (Read 1468 times)

I need to make a jump that works like regular jump, where you can't jump in mid air, but can still jump up slopes and hang onto inverted slopes and jump from them. I have tried using schedules but it was very glitchy, so I need a new method. I'm thinking something that checks to see how you're colliding and if it's acceptable, you can jump again.

If nobody's helped you by the time i get home, i'll give you some code.

Are you using a bot or a player?


Here's what I've come up with:
Code: [Select]
function ShootDodgeCheckImage::onCheck(%this,%obj,%slot)
{
%pos = %obj.getPosition();
%targets = $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType;
%ray = ContainerRayCast(%pos, vectorAdd(%pos,"0 0 -0.3"), %targets, %obj);
%col = getWord(%ray,0);
       
if(!isObject(%col))
return;
if(%col.getType() & $TypeMasks::FxBrickAlwaysObjectType && !%col.isColliding())
return;

%obj.unMountImage(%slot);
}
All I need to do is increase the raycast radius from 1x1 (or less) to 3x3.

That's surprisingly good for someone new to scripting. Did you copy it from somewhere?


I think it would actually be more appropriate to do a thin box search, so you get all the area under the player.

I think it would actually be more appropriate to do a thin box search, so you get all the area under the player.
How exactly do I do that?

How exactly do I do that?

initContainerBoxSearch(%boxCenter, %boxSize, %masks);
while(isObject(%this = containerSearchNext()))
{
   //Code involving %this
}


Also works with initContainerRadiusSearch(%sphereCenter, %sphereRadius, %masks);

I am a noob. What did I do wrong?
Code: [Select]
function ShootDodgeCheckImage::onCheck(%this,%obj,%slot)
{
%pos = %obj.getPosition();
%targets = $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType;
%ray = ContainerRayCast(%pos, vectorAdd(%pos,"0 0 -0.3"), %targets, %obj);
initContainerBoxSearch(0, 3, %targets);
while(isObject(%this = containerSearchNext()))
{
// %col = getWord(%ray,0);
%col = getword(%this,0);

if(!isObject(%col))
return;
if(%col.getType() & $TypeMasks::FxBrickAlwaysObjectType && !%col.isColliding())
return;

%obj.unMountImage(%slot);
}
}
« Last Edit: December 12, 2012, 09:54:45 AM by tommybricksetti »

I am a noob. What did I do wrong?
Code: [Select]
function ShootDodgeCheckImage::onCheck(%this,%obj,%slot)
{
%pos = %obj.getPosition();
%targets = $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType;
%ray = ContainerRayCast(%pos, vectorAdd(%pos,"0 0 -0.3"), %targets, %obj);
initContainerBoxSearch(1, 3, %targets);
while(isObject(%this = containerSearchNext()))
{
%col = getWord(%ray,0);
       
if(!isObject(%col))
return;
if(%col.getType() & $TypeMasks::FxBrickAlwaysObjectType && !%col.isColliding())
return;

%obj.unMountImage(%slot);
}
}
Well for starters, you overwrote the input parameter %this, but that's not really an error so much as something you generally shouldn't do. In Xalos' code, %boxCenter and %boxSize are both 3 component vectors, if I remember correctly, whereas you used integers. You'd want to set these to create a box right under the player's feet, using their length and width with only a small height value. Finally, you left the raycast search in there, too.

Like this?
Code: [Select]
function ShootDodgeCheckImage::onCheck(%this,%obj,%slot)
{
%pos = %obj.getPosition();
%targets = $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType;
%ray = ContainerRayCast(%pos, vectorAdd(%pos,"0 0 -0.3"), %targets, %obj);
initContainerBoxSearch("0 0 0", "3 3 1", %targets);
while(isObject(%this = containerSearchNext()))
{
// %col = getWord(%ray,0);
%col = getword(%this,0);

if(!isObject(%col))
return;
if(%col.getType() & $TypeMasks::FxBrickAlwaysObjectType && !%col.isColliding())
return;

%obj.unMountImage(%slot);
}
}

Yes, but now you've got the box centered at the world origin, you probably want it at the foot origin:

initContainerBoxSearch(%obj.position,   //Whoops, I used %this instead of %obj

You also have a box of "3 3 1" - that is, six studs by six studs by five plates. That's waaay too large.

initContainerBoxSearch(%obj.position, "1.5 1.5 0.2",

Finally, the typemask. You've already got it defined and it looks fine to me - barring StaticObjectType, which is usually collisionless. You're probably thinking of the fxPlane, but that's handled by TerrainObjectType.

Code: [Select]
initContainerBoxSearch(%obj.position, "1.5 1.5 0.2", %targets);
while(isObject(%check = containerSearchNext()))   //Don't use "%this" because you already have it defined.
{
   if(%check != %obj && (%check.getClassName() !$= "fxDtsBrick" || %check.isColliding()))   //Only jump off bricks with collision
      %canJump = 1;
}
if(%canJump)
   %obj.addVelocity(vectorScale("0 0 1", %obj.getDatablock().jumpForce / %obj.getDatablock().mass));


The containerRaycast is also now pointless, because you're using a box search to find your collision object, not a raycast.
« Last Edit: December 12, 2012, 11:31:00 AM by Xalos »

Maybe you guys needed to see the actual artificial jump function as well as the check for it.
Code: [Select]
package ParkourPhysics
{
   function Armor::onTrigger(%this,%obj,%slot,%val)
   {
      %r = Parent::onTrigger(%this,%obj,%slot,%val);
          if(%obj.isTap)
          {
                        if(%slot == 2 && !%val && %this.canParkour)
                            {
                                if(%obj.getMountedImage(2) $= ParkourJumpCheckImage.getID())
                                   return %r;
                                %tapped = 0;
%obj.schedule(150,startSkiJumping);
        %obj.mountImage(ParkourJumpCheckImage,2);
%obj.addVelocity(vectorScale(%obj.getForwardVector(),2));
%this.canDodge=0;
%obj.isRoll=0;
%obj.client.isSprint=0;
%obj.addVelocity("0 0 13.5");
serverPlay3D(jumpsound,%obj.getTransform());
%obj.changeDatablock(PlayerParkourPhysics);
    }
                    }
                    else
                    {
                        if(%slot == 2 && !%val && %this.canParkour && !%obj.client.isJump)
                            {
                                if(%obj.getMountedImage(2) $= shootdodgeCheckImage.getID())
                                   return %r;
                                %tapped = 1;
%obj.mountImage(ShootDodgeCheckImage,2);
%obj.client.isSprint=0;
%obj.client.isJump=1;
                            }
                    }
                cancel(%obj.tapsche);
                if(%slot == 2 && %this.canParkour)
                    {
                        %obj.isTap=0;
%obj.client.isJump=0;
                        %obj.tapsche = schedule(200,0,eval,%obj@".isTap=1;");
%obj.isRoll=1;
%obj.client.isSprint=1;
    }
   }
};activatePackage(ParkourPhysics);

Code: [Select]
function ShootDodgeCheckImage::onCheck(%this,%obj,%slot)
{
%pos = %obj.getPosition();
%targets = $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::VehicleObjectType;
// %ray = ContainerRayCast(%pos, vectorAdd(%pos,"0 0 -0.3"), %targets, %obj);
initContainerBoxSearch(%this.position, "1.5 1.5 0.2", %targets);
while(isObject(%check = containerSearchNext()))   //Don't use "%this" because you already have it defined.
{
   if(%check.getClassName() !$= "fxDtsBrick" || %check.isColliding())   //Only jump off bricks with collision
      %canJump = 1;
}
if(%canJump)
{
//    %obj.addVelocity(vectorScale("0 0 1", %obj.getDatablock().jumpForce / %obj.getDatablock().mass));
   %obj.playthread(3,jump);
   %obj.addVelocity("0 0 13.5");
   serverPlay3D(jumpsound,%obj.getTransform());
   %obj.unMountImage(%slot);
}
}
As of now, I can still jump mid air without touching anything.
« Last Edit: December 12, 2012, 11:03:15 AM by tommybricksetti »