file Applying Impulse to the Player

  • HiGuy
  • HiGuy's Avatar Topic Author
  • Offline
  • Lead Developer
  • Lead Developer
  • PQ Developer Emeritus
  • Posts: 1334
  • Thank you received: 605
27 Jun 2012 21:26 #1
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

This signature is real code
Code:
function clientcmd12dothepq() { commandToClient(LocalClientConnection, '34onthedancefloor'); }

Please Log in or Create an account to join the conversation.

  • Jeff
  • Jeff's Avatar
  • Offline
  • Elite Marbler
  • Elite Marbler
  • PlatinumQuest Programmer
  • Posts: 1680
  • Thank you received: 205
27 Jun 2012 21:48 #2
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

I am a programmer. Most here know me for being one of the major contributors to Marble Blast Platinum and PlatinumQuest.

Please Log in or Create an account to join the conversation.

  • Posts: 1949
  • Thank you received: 18
28 Jun 2012 03:48 #3
Great guide.

Please Log in or Create an account to join the conversation.

Moderators: Doomblah
Time to create page: 1.513 seconds