Game Scripting
-
- Posts: 4132
- Joined: Tue Oct 21, 2008 5:20 pm
- Location: Washington, USA
- Contact:
Game Scripting
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?
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?
Re: Game Scripting
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!
Good to see you around guy. I'm still honored I got to eat at bdubs with you!
TeamHavocRacing wrote:If I had a nickel for every time someone asked for this, I would have a whole shitload of nickels.
Re: Game Scripting
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
-
- Posts: 4132
- Joined: Tue Oct 21, 2008 5:20 pm
- Location: Washington, USA
- Contact:
Re: Game Scripting
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?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.
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]);
}
-
- Posts: 4132
- Joined: Tue Oct 21, 2008 5:20 pm
- Location: Washington, USA
- Contact:
Re: Game Scripting
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...
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...
Re: Game Scripting
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.
"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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
Re: Game Scripting
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.
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
-
- Posts: 4132
- Joined: Tue Oct 21, 2008 5:20 pm
- Location: Washington, USA
- Contact:
Re: Game Scripting
Glad I'm not completely crazy!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.
Re: Game Scripting
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.
Re: Game Scripting
Explains why I couldn't get my man to bounce. Had to resort to using the z axis instead.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.
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;
}
Re: Game Scripting
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;
}
Re: Game Scripting
mx sim soccer championship coming up...DJ99X wrote:
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; }
Re: Game Scripting
That's what I was thinking 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
-
- Posts: 4132
- Joined: Tue Oct 21, 2008 5:20 pm
- Location: Washington, USA
- Contact:
Re: Game Scripting
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?DJ99X wrote:That's what I was thinking 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
Re: Game Scripting
I wasn't sure if that was absolute velocity or not, I didn't try it.