Game Scripting

All about making tracks for MX Simulator
User avatar
wheels1758
Posts: 4129
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Game Scripting

Postby wheels1758 » Sat Jan 19, 2019 9:44 pm

I'm curious what people are coming up with for in-game scripting. Objects moving, flying, interactions with the leaderboard/laptimes, etc.

JLV, is there currently a way to enable/disable sequence files (i.e. turning on/off the loop variable) with javascript, or would you have to manually change the texture based on game timing?

User avatar
yzmxer608
Posts: 15347
Joined: Mon Dec 29, 2008 4:30 am
Team: SYS
Location: Wisconsin, U.S.A

Re: Game Scripting

Postby yzmxer608 » Sat Jan 19, 2019 10:19 pm

Most things that I know of that have been done are in the snapshot topic. The rF SX tracks have had the scoring pylon things working. That I know of nothing has been done for finish lines etc. JLV did make a nice template to see how things work for the laptime interactions. I need to do some python learning before I dive more into the mxs specific stuff.

Good to see you around guy. I'm still honored I got to eat at bdubs with you! :mrgreen:
TeamHavocRacing wrote:If I had a nickel for every time someone asked for this, I would have a whole shitload of nickels.

jlv
Site Admin
Posts: 13490
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Game Scripting

Postby jlv » Sun Jan 20, 2019 2:42 am

You can't change the seq settings. If you want to do a custom loop you want to set the seq to not loop and do all the updates in the script.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.

User avatar
wheels1758
Posts: 4129
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Re: Game Scripting

Postby wheels1758 » Sun Jan 20, 2019 2:54 am

jlv wrote:You can't change the seq settings. If you want to do a custom loop you want to set the seq to not loop and do all the updates in the script.


That's what I was playing around with. I notice that you set the animation time to 512 in your javascript test, but it is not a loop. Was that just a carry-over from some sequence file you copied?

Also, I am messing around with mx.move_statue and the Y axis doesn't seem to be working. Is that something I'm doing wrong?

Code: Select all

var p;
if (g_leader_slot >= 0) {
   p = mx.get_position(g_leader_slot);
   mx.move_statue(0, p[0], p[1] + 10, p[2]);
}

User avatar
wheels1758
Posts: 4129
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Re: Game Scripting

Postby wheels1758 » Sun Jan 20, 2019 2:57 am

I guess I should clarify. Green cube does follow the leader, but it's always on the ground no matter the leader's Y position (relative to game 0 or ground). When I hit a jump, green cube stays on the ground, like a 3 dimensional 12 o'clock shadow.

I'm not sure how aaron5r got the plane to fly. I'm wondering if his plane "center" is 30 feet below the actual plane...

jlv
Site Admin
Posts: 13490
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Game Scripting

Postby jlv » Sun Jan 20, 2019 3:29 am

Yes, 512 was just what was already there. Since it was one frame it didn't matter.

"get_position" returns an absolute position, whereas "move_statue" interprets the Y value as ground relative. If you use the Y value from get_position it should wind up around double the rider's elevation. (If the rider is on ground 50 feet above 0, the Y will be a little over 50, so move_statue will set the Y to ~50 above the ground, so around 100.) The only explanation I can think of is the track's elevation was under 0. I'll have to give it a test.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.

jlv
Site Admin
Posts: 13490
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Game Scripting

Postby jlv » Sun Jan 20, 2019 3:41 am

Just double checked it and it's a bug. The Y value gets overwritten when it positions the statue on the ground. There's a separate value for the ground relative height that I should have set.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.

User avatar
wheels1758
Posts: 4129
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Re: Game Scripting

Postby wheels1758 » Sun Jan 20, 2019 4:03 am

jlv wrote:Just double checked it and it's a bug. The Y value gets overwritten when it positions the statue on the ground. There's a separate value for the ground relative height that I should have set.


Glad I'm not completely crazy!

aaronr5
Posts: 593
Joined: Wed Dec 29, 2010 8:03 am
Team: DAM
Location: North Carolina

Re: Game Scripting

Postby aaronr5 » Sun Jan 20, 2019 5:21 am

I used a single bone in the plane and just position the bone rather than using move_statue like you had suggested jlv. I know you said you would probably add a move_statue that isn't ground relative but this works for now.

Image

User avatar
DJ99X
Posts: 15503
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Game Scripting

Postby DJ99X » Mon Jan 21, 2019 11:10 am

jlv wrote:Just double checked it and it's a bug. The Y value gets overwritten when it positions the statue on the ground. There's a separate value for the ground relative height that I should have set.


Explains why I couldn't get my man to bounce. Had to resort to using the z axis instead.

Image

Does it only look at frills.js? Or should it read any script located in the folder? I guess mx.frame_handler can only be defined once.

Here is my bouncing man script

Code: Select all

var statue_index = 0;
var x_pos = 1500;
var y_pos = 4;
var z_pos = 1042;
var x_vel = 5;
var z_vel = 30;
var grav = 32.174;
var rot = 0;
var t_d =0;
var t_s =0;
var t_e =0;
var landing_damping = 0.1;
mx.message("Jumping Jack Test");

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);

mx.frame_handler = function(seconds) {
t_s = seconds;   
var t_d = t_s - t_e;
x_pos = x_pos + x_vel*t_d;
z_vel = z_vel - grav*t_d;
z_pos = z_pos + z_vel*t_d;
rot = rot + t_d*2*Math.PI/4;
if (rot > Math.PI) {
   rot = rot - 2*Math.PI;
}

if (z_pos<1042) {
   z_pos = 1042;
   z_vel = -z_vel*(1-landing_damping);
}

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);
t_e = seconds;
}

User avatar
DJ99X
Posts: 15503
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Game Scripting

Postby DJ99X » Mon Jan 21, 2019 12:06 pm

Image


Code: Select all

var statue_index = 0;
var x_pos = 1500;
var y_pos = 4;
var z_pos = 1042;
var x_vel = 0;
var z_vel = 0;
var rot = 0;
var t_s =0;
var t_e =0;
var damping = 0.001;
var Rider_Pos, Rider_X, Rider_Z, Rider_Vel_X, Rider_Vel_Y, Abs_Dist;
var Rider_X_Old = 0;
var Rider_Z_Old = 0;
var Contact_Radius = 3;
mx.message("Hit Him");

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);

mx.frame_handler = function(seconds) {
t_s = seconds;   
var t_d = t_s - t_e;

Rider_Pos = mx.get_position(0);


 Rider_X = Rider_Pos[0];
 Rider_Z = Rider_Pos[2];
 Rider_Vel_X = (Rider_X - Rider_X_Old)/t_d;
 Rider_Vel_Z = (Rider_Z - Rider_Z_Old)/t_d;
 var Rider_Vel = Math.sqrt(Rider_Vel_X*Rider_Vel_X+Rider_Vel_Z*Rider_Vel_Z);
 

 
 Abs_Dist = Math.sqrt((Rider_X-x_pos)*(Rider_X-x_pos)+(Rider_Z-z_pos)*(Rider_Z-z_pos));

 if (Abs_Dist < Contact_Radius) {
    x_vel = Rider_Vel_X;
    z_vel = Rider_Vel_Z;
 }


x_pos = x_pos + x_vel*t_d;
z_pos = z_pos + z_vel*t_d;

rot = rot + t_d*2*Math.PI/4;
if (rot > Math.PI) {
   rot = rot - 2*Math.PI;
}


x_vel = x_vel*(1-damping);
z_vel = z_vel*(1-damping);

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);


t_e = seconds;
Rider_X_Old = Rider_X;
Rider_Z_Old = Rider_Z;

}

User avatar
AtlasZoor
Posts: 302
Joined: Wed Aug 02, 2017 12:51 am
Team: Atlas Trackworks
Location: Zimbabwe

Re: Game Scripting

Postby AtlasZoor » Mon Jan 21, 2019 4:47 pm

DJ99X wrote:Image


Code: Select all

var statue_index = 0;
var x_pos = 1500;
var y_pos = 4;
var z_pos = 1042;
var x_vel = 0;
var z_vel = 0;
var rot = 0;
var t_s =0;
var t_e =0;
var damping = 0.001;
var Rider_Pos, Rider_X, Rider_Z, Rider_Vel_X, Rider_Vel_Y, Abs_Dist;
var Rider_X_Old = 0;
var Rider_Z_Old = 0;
var Contact_Radius = 3;
mx.message("Hit Him");

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);

mx.frame_handler = function(seconds) {
t_s = seconds;   
var t_d = t_s - t_e;

Rider_Pos = mx.get_position(0);


 Rider_X = Rider_Pos[0];
 Rider_Z = Rider_Pos[2];
 Rider_Vel_X = (Rider_X - Rider_X_Old)/t_d;
 Rider_Vel_Z = (Rider_Z - Rider_Z_Old)/t_d;
 var Rider_Vel = Math.sqrt(Rider_Vel_X*Rider_Vel_X+Rider_Vel_Z*Rider_Vel_Z);
 

 
 Abs_Dist = Math.sqrt((Rider_X-x_pos)*(Rider_X-x_pos)+(Rider_Z-z_pos)*(Rider_Z-z_pos));

 if (Abs_Dist < Contact_Radius) {
    x_vel = Rider_Vel_X;
    z_vel = Rider_Vel_Z;
 }


x_pos = x_pos + x_vel*t_d;
z_pos = z_pos + z_vel*t_d;

rot = rot + t_d*2*Math.PI/4;
if (rot > Math.PI) {
   rot = rot - 2*Math.PI;
}


x_vel = x_vel*(1-damping);
z_vel = z_vel*(1-damping);

mx.move_statue(statue_index, x_pos, y_pos, z_pos, rot);


t_e = seconds;
Rider_X_Old = Rider_X;
Rider_Z_Old = Rider_Z;

}


mx sim soccer championship coming up...
Image

User avatar
DJ99X
Posts: 15503
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Game Scripting

Postby DJ99X » Mon Jan 21, 2019 6:40 pm

That's what I was thinking :lol: I don't think it would sync up to well between clients though. Even when I played back the demo, there were slight differences in position which made the statue move differently

User avatar
wheels1758
Posts: 4129
Joined: Tue Oct 21, 2008 5:20 pm
Location: Washington, USA
Contact:

Re: Game Scripting

Postby wheels1758 » Mon Jan 21, 2019 7:05 pm

DJ99X wrote:That's what I was thinking :lol: I don't think it would sync up to well between clients though. Even when I played back the demo, there were slight differences in position which made the statue move differently


That’s hilarious DJ! Just skimming the code, is there a reason you calculate velocity from previous position and current position rather than using mx.get_velocity?

User avatar
DJ99X
Posts: 15503
Joined: Tue Jan 15, 2008 11:36 am
Location: Land Down Under

Re: Game Scripting

Postby DJ99X » Mon Jan 21, 2019 7:34 pm

I wasn't sure if that was absolute velocity or not, I didn't try it.


Return to “Track Editing”

Who is online

Users browsing this forum: No registered users and 1 guest