Author Topic: AddVelocity in the opposite direction of an object  (Read 951 times)



I'm assuming it would be easy with vectors, but I'm really bad at using them.

Try this:
%player.setVelocity(vectorAdd(%player.getVelocity(), vectorAdd(vectorScale(%obj.getForwardVector(), velocity), "0 0" SPC verticalVelocity)));
Replace velocity with the amount of velocity you want the player to travel at.
Replace verticalVelocity with the how high you want the player to go.
« Last Edit: March 06, 2014, 08:44:35 PM by jes00 »

Try this:
%player.setVelocity(vectorAdd(%player.getVelocity(), vectorAdd(vectorScale(%obj.getForwardVector(), velocity), "0 0" SPC verticalVelocity)));
Replace velocity with the amount of velocity you want the player to travel at.
Replace verticalVelocity with the how high you want the player to go.
That's the opposite of the player's current forward vector.

I mean to push them in the direction opposite of "object".

//Assumed variables:
//%pl = the player object
//%obj = the object to repel from
//%force = the strength of the force

%dir = vectorNormalize(vectorSub(%obj.getPosition(), %pl.getHackPosition()));   //Then - now, or in this case, now - goal.
%pl.addVelocity(vectorScale(%dir, %force));   //addVelocity is a default function for player objects. What's going through jes00's mind, I don't know.

//Assumed variables:
//%pl = the player object
//%obj = the object to repel from
//%force = the strength of the force

%dir = vectorNormalize(vectorSub(%obj.getPosition(), %pl.getHackPosition()));   //Then - now, or in this case, now - goal.
%pl.addVelocity(vectorScale(%dir, %force));   //addVelocity is a default function for player objects. What's going through jes00's mind, I don't know.
It seems to pull players toward the object.

It seems to pull players toward the object.
Try using negative force


vectorSub(%obj.getPosition(), %pl.getHackPosition());
change it to
vectorSub(%pl.getHackPosition(), %obj.getPosition());
that should reverse it(?)

vectorSub(%obj.getPosition(), %pl.getHackPosition());
change it to
vectorSub(%pl.getHackPosition(), %obj.getPosition());
that should reverse it(?)
Yes.

Or you can just scale the vector by -1. Using Xalos's code if you used a force of -1 it should work.

This method works great:

Code: [Select]
%dir = vectorNormalize(vectorSub(%obj.getHackPosition(), %this.getPosition()));
%obj.addVelocity(vectorScale(%dir, (%obj.isCrouched() ? 1 : 2)));

However, i'd also like it to fire a raycast between the player and the object, make sure there are no bricks, and then addVelocity. But, again, I suck at raycasts/vectors.

Code: [Select]
function isObstruction(%pos,%player)
{
   %object = ContainerRayCast(%pos,%player.getEyePoint(), $TypeMasks::FxBrickObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::VehicleObjectType, %player);

   %obstr = getWord(%object,0);
   if(isObject(%obstr) && %obstr.getDatablock().getName() !$= "brick4x1x5windowData")
      return 1;
   else
      return 0;
}

Code: [Select]
function isObstruction(%pos,%player)
{
   %object = ContainerRayCast(%pos,%player.getEyePoint(), $TypeMasks::FxBrickObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::VehicleObjectType, %player);

   %obstr = getWord(%object,0);
   if(isObject(%obstr) && %obstr.getDatablock().getName() !$= "brick4x1x5windowData")
      return 1;
   else
      return 0;
}
I already figured it out, thanks tho.

And why are you using the eye point?

I already figured it out, thanks tho.

And why are you using the eye point?
I just copypasted some code. I expected you would know best how to adjust it for your needs.