Author Topic: Apply impulse in the direction that an object hits it.  (Read 684 times)

Code: [Select]
package push{
function Armor::onCollision(%this, %obj, %col, %thing, %other){
if(%col.getDatablock().getName() $= "WCubeVehicle"){
%start = %obj.getEyePoint();
%end = vectorAdd(vectorScale(vectorNormalize(%obj.getEyeVector()), 5), %start);
%vehicle = ContainerRayCast(%start, %end, $TypeMasks::VehicleObjectType);
if(%vehicle){
if(%vehicle.getDatablock().getName() $= "WCubeVehicle"){
echo(%obj.getVelocity());
%col.setVelocity(%obj.getVelocity());
}
}
}
parent::OnCollision(%this, %obj, %col, %thing, %other);
}
};
activatePackage(push);

I'm trying to make it so when you walk into the weighted companion cube you push it in direction you're trying to walk but that doesn't want to let you push it.

The raycast is there to make it so you can only push it if you're facing it.
« Last Edit: November 11, 2007, 07:33:40 AM by MrPickle »

Code: [Select]
%col.setVelocity(vectorScale(%obj.getForwardVector(),3));Instead of the setvelocity bit you have.

Isn't normalising the normal of something a little redundant? (This bit:)

Code: [Select]
vectorNormalize(%obj.getEyeVector())
What actually happens when you try and push it? My code will only work if it DOES push, but not the right way or something.

It moves if you're side stepping while walking into it, it moves sideways like you.

If you walk straight into it it just sits there.

That works.
« Last Edit: November 11, 2007, 08:12:55 AM by MrPickle »