Author Topic: What are radius impulses? Black holes? Forcefields? Time travel? Momentum?  (Read 2738 times)

I found a topic about it while searching, but I still don't exactly understand. I know it has something to do with applying velocity. Does it function similarly to the add velocity function? I'm trying to make something like a black hole. What does it do? What are its uses? Forcefeilds?

Is this the code to drag something to a position?
%impulseVec = VectorSub(%targetObject.getWorldBoxCenter(), %position);
%impulseVec = VectorNormalize(%impulseVec);
%impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
%targetObject.applyImpulse(%position, %impulseVec);

Can someone explain it to me? What exactly are they trying to do?

Edit: Another problem is that I'm creating this class, similar to Overwatch's Tracer, where your special ability is to go back in time. Your position/health/weapons/ammo gets restored. I was wondering what the most efficient way to do this was. In order to teleport back, would I have to individually save the player's position every second? Or is there an easier way? Also, is there a setHealth command? Another one, is there a way to easily stop momentum on a player, or do I just have to addVelocity in the opposite direction?
« Last Edit: June 20, 2015, 04:20:10 PM by Johnny Blockhead »

I found a topic about it while searching, but I still don't exactly understand. I know it has something to do with applying velocity. Does it function similarly to the add velocity function? I'm trying to make something like a black hole. What does it do? What are its uses?

Is this the code to drag something to a position?
%impulseVec = VectorSub(%targetObject.getWorldBoxCenter(), %position);
%impulseVec = VectorNormalize(%impulseVec);
%impulseVec = VectorScale(%impulseVec, %impulse * %distScale);
%targetObject.applyImpulse(%position, %impulseVec);

Can someone explain it to me? What exactly are they trying to do?
Impulses are similar to the add velocity function in that they both add motion.
The main and crucial thing to remember is that impulses add the velocity relative to a location.

In this example, the dot at the top is this code
BlackDot1.addVelocity("5 0 0");
While the dot at the bottom is
BlackDot1.applyImpulse(RedDot.getPosition(),"500 0 0");
This is why the 1st blue dot goes directly right, and the 2nd is skewered
The force isn't being applied directly, rather it's being applied slightly below and to the left, so it leaves the dot slightly higher than it would if the position was right behind the black dot.

This is also the reason why Rocket Launchers don't always give people the same blast. They do a radius search for the people hit, and blast them away from the center of the explosion, which in many cases, results in different knock backs due to different positions.

In the example code, a negative force is created which infact would pull people toward the center given enough strength from the impulse and other factors. If you want me to go more indepth just ask.

Edit: Another problem is that I'm creating this class, similar to Overwatch's Tracer, where your special ability is to go back in time. Your position/health/weapons/ammo gets restored. I was wondering what the most efficient way to do this was. In order to teleport back, would I have to individually save the player's position every second? Or is there an easier way?
The best solution would probably be to have a loop or some way of checking every second yes.
Proceed to store ammo / health / position / weapons everytime the loop is run. If anyone else has a cleaner idea, go ahead.
Also, is there a setHealth command?
I'm sure there's a %player.setHealth(amount); command since it's an event and all events can be called through code. You might want to also look into the functions %player.setDamageLevel(); (This is setHealth but on a more basic and raw level) and %player.getDamageLevel(); (This is getHealth but on a more basic and raw level). DamageLevels are essentially how much damage you've taken thus far vs how much health you're missing thus far.
Another one, is there a way to easily stop momentum on a player, or do I just have to addVelocity in the opposite direction?
%player.setVelocity("0 0 0"); ?
« Last Edit: June 20, 2015, 04:26:08 PM by Alphadin »

Wow, thank you! You gave a very clear definition of pretty much everything. It's very simple now.
« Last Edit: June 20, 2015, 05:07:56 PM by Johnny Blockhead »

radius impulse is mostly just an explosion without the damage, pretty sure explosions USE it for the movement
1st argument is range, 2nd is power, 3rd is upward velocity

here's some events that i use for an orbiter (a brick (4x cube) suspended 3 or so 64x cubes up)
Code: [Select]
EVENTS 9
1 0 onActivate Self decrementPrintCount 9
1 0 onActivate Self decrementPrintCount 9
1 33 onPrintCountUnderFlow Self decrementPrintCount 9
1 33 onPrintCountUnderFlow Self decrementPrintCount 9
1 0 onPrintCountUnderFlow Self radiusImpulse 100 -450 200
0 0 onPlayerTouch Player SetVelocity 50 0 50
1 0 onPlayerTouch Player SetVelocity -50 0 -50
1 750 onPlayerTouch Player SetVelocity 0 50 -50
1 0 onPlayerTouch Self toggleEventEnabled 5 6
click the brick to start it pulling you in, if you hit the brick, it will just launch you out and you'll start spinning around it
it uses a printcount loop so that multiple players can use the same brick
with relays only one player could use it at once

radius impulse is mostly just an explosion without the damage, pretty sure explosions USE it for the movement
Hmm, I always thought that explosions were handled through this process
Radius search (Damage)
Does damage based on distance using the radius search distance output
Radius search (Impulse)
Does impulse based on distance using the radius search distance output

seems like it would make more sense to use the radius impulse function that's already there, since it does all of that secondary impulse fun shenanigans
the damage might be done with a radius search though

I'm trying to get a test of it to work, but all the script does is the same as what addVelocity yields, just weaker. I tried adding negative values but that just reversed the direction. Nothing changes when I move around the location. I'm sure the coordinates are being saved to the client...

function servercmdT(%client)
{
   %client.player.applyImpulse(%client.s, "0 0 -2000");
}
function servercmdS(%client)
{
   %client.s = %client.player.getPosition();
}

Edit: Alphadin was awesome and showed me how to do the math in order to get it working.
« Last Edit: June 20, 2015, 09:34:08 PM by Johnny Blockhead »

Radius impulse is used by explosions. It essentially does a radius search, calculates the distance from the origin point and the object found, then uses mCos(pi * (1-(distance/maxdist))) * magnitude as the magnitude of an impulse in the direction vectorNormalize(vectorSub(position, origin)). It just does that engine side so it's much faster. It also is much less code to just call the radius impulse function than to write that all out.

In order to pull players in, you multiply the amount of force you want by the distance divided by the maximum distance (so, 2500 * %distance/20). I'm having a hard time figuring out how to reverse this, since in the current one when %distance gets closer to 20, the force becomes stronger. 2500 is the maximum force someone would experience. But, what would I do to make it so the closer to 1, the stronger the (reverse) force? Also, how do I reverse the direction? Do I have to subtract it differently?

Edit: I figured out how to reverse the direction. You just subtract the target player from the initiator, instead of the other way around. I still need to know about the gravity.
« Last Edit: June 21, 2015, 12:51:03 PM by Johnny Blockhead »

Radius impulse is used by explosions. It essentially does a radius search, calculates the distance from the origin point and the object found, then uses mCos(pi * (1-(distance/maxdist))) * magnitude as the magnitude of an impulse in the direction vectorNormalize(vectorSub(position, origin)). It just does that engine side so it's much faster. It also is much less code to just call the radius impulse function than to write that all out.
it doesn't do a vector add for the upwards velocity?

pretty sure it takes three arguments besides positions, the radius, force of the push, and an upwards push

I still need to know about the gravity.
what about gravity?
do you want to counteract it so that people don't fall down and instead get sucked in?

No, by gravity I mean the pull/push force. Right now, the closer you get to the center the weaker the force is. The farther, the stronger. I want it so when you're closer, there is a stronger force. How do you do that?

Edit: Current code.
%target = %tPlayer.getHackPosition();
%initiator = %client.player.getHackPosition();
%direction = vectorSub(%initiator, %target);
%direction = vectorNormalize(%direction);
%tPlayer.applyImpulse(%target,vectorScale(%direction,2500*%dist/12)) //Relevant part
« Last Edit: June 21, 2015, 01:19:15 PM by Johnny Blockhead »

it doesn't do a vector add for the upwards velocity?

pretty sure it takes three arguments besides positions, the radius, force of the push, and an upwards push
You're talking about the brick class. We are using applyImpulse not radiusImpulse.

You're talking about the brick class. We are using applyImpulse not radiusImpulse.
can you not use radius impulse on other things?
it seems like it should be able to be used outside of bricks, since it's basically an explosion
plan B is just spam explosions that pull people in, and not have particles or anything for the explosion

%tPlayer.applyImpulse(%target,vectorScale(%direction,2500*%dist/12)) //Relevant part
try %tPlayer.applyImpulse(%target, vectorScale(%direction, 2500 * 12 / %dist));
or, simplified math %tPlayer.applyImpulse(%target, vectorScale(%direction, 30000 / %dist));
in that way, the pull will get hugely strong as you get close
if you wanted a linear scaling, you could use 2500 * (%maxdist - %dist) / 12 for the vector scale

let me know about how you want it to scale with distance, linear/exponentially/other rates, and what the max distance of the pull should be with what force
it's mostly just playing with the numbers a little bit

can you not use radius impulse on other things?
Seems only for bricks.

found a radiusdamage function, maybe that's what explosions use to call a projectile's radiusdamage function
not sure how explosions go about pushing everything