Hi Guy Expert Marbler
    TorqueScript Hacking Maniac[ss:Blue Groove (MF)] member is offline
![[avatar] [avatar]](http://higuysmb.heliohost.org/images/spec/nope.gif)
If you can see my avatar, then my server is still functioning.
Joined: Mar 2008 Gender: Male  Posts: 610 Location: Both nowhere and everywhere...
|  | Applying Impulse to the Player « Thread Started on Jun 28, 2012, 5:26am » | |
Now, some of you may know about the command .applyImpulse(). This self-explanatory command can be very useful to mod makers. Basically, it will apply an impulse, or push, to any object with a start point and a vector of impulse. Basic command syntax is as follows:
Code:%object.applyImpulse(%start, %vector);
|
|
Here's an example with values:
Code:%object.applyImpulse("0 0 -1" "0 0 3");
|
|
This snippet here will apply an impulse to the object from 1 block below the object's center, with an upwards force of 3.
You're probably thinking, "that's how the blast works," but there is another hidden step there. See, if you try to impulse the marble, it will reset camera direction, movement speed, and any other input factors affecting the marble. As well, normal impulses applied to the marble will "stack up," meaning that if you apply later impulses, they will also re-apply the previous impulses. Basically, don't impulse LocalClientConnection.player.
But fear not! Jeff and I found a solution to this while working on PR. The solution can be found in blast.cs and it is in most of my recent codes. The basic concept is that you have to find the client-side marble. LocalClientConnection.player is server-side, as you can find it in MissionCleanup. Jeff and I discovered that you can scour the contents of ServerConnection (yes, a GameConnection object) for the marble, although none of the objects in ServerConnection have names or custom values. All that they have is datablocks and classnames, so we used classnames to find the marble. Here is the basic syntax for finding the client-side marble:
Code://Snip from blast.cs
function findRealMarble() { //Iterate through all objects in client-side server connection for (%i = 0; %i < ServerConnection.getCount(); %i ++) { //Get the object from the iteration %obj = ServerConnection.getObject(%i); //Check for ID. The marble ID will *always* be higher. //Analysis shaped by using tree(); //tree(); is one of those hidden-but-useful functions if (%obj.getId() < LocalClientConnection.player.getId()) continue; //If it's a marble, then we're good! //This is *guarenteed* to be the client-side marble, 100% //of the time, if you are playing single player if (%obj.getClassName() $= "Marble") { return %obj; } } }
|
|
From there, you can simply run:
Code:findRealMarble().applyImpulse("0 0 -1", "0 0 10000");
|
|
And shoot your marble out into space with no side-effects (besides being in space).
HiGuy
|
Definitely On-Topic MBP Coding ![[image] [image]](http://i.imgur.com/lqCvtpQ.png) |
|
Jeff Elite Marbler
     torqueScript maniac[ss:Default Skin] member is offline
MBP Leaderboard Moderator.
Joined: Nov 2010 Gender: Male  Posts: 1,559 Location: Kicking people from LBs...
|  | Re: Applying Impulse to the Player « Reply #1 on Jun 28, 2012, 5:48am » | |
I've been waiting for you to do this, however, i thought serverConnection was the server side (oops) thats why if you look to what i've coded higuy in pr/mbelite you see
// Jeff: find the server object
sorry about that, thanks for clarifying that haha. Yeah, this i couldn't believe when we discovered the trick to impulsing the marble. This impulse thing was used for many things...such as higuy said the blast. Without this find, multiplayer couldn't even live up to its full potential!
If you have two marble objects...then things get trickier....
Jeff
|
|
|
Pablo Global Moderator
        PQ Map Engineer[ss:Default Skin] member is offline
![[msn] [msn]](http://images.proboards.com/new/msn.png)
![[homepage] [homepage]](http://images.proboards.com/new/buttons/www_sm.png) Joined: Mar 2007 Gender: Male  Posts: 12,305
|  | Re: Applying Impulse to the Player « Reply #2 on Jun 28, 2012, 11:48am » | |
Great guide.
|
|
|