Page 1 of 3

Game Scripting

Posted: Sat Jan 19, 2019 9:44 pm
by wheels1758
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?

Re: Game Scripting

Posted: Sat Jan 19, 2019 10:19 pm
by yzmxer608
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:

Re: Game Scripting

Posted: Sun Jan 20, 2019 2:42 am
by jlv
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.

Re: Game Scripting

Posted: Sun Jan 20, 2019 2:54 am
by wheels1758
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]);
}

Re: Game Scripting

Posted: Sun Jan 20, 2019 2:57 am
by wheels1758
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...

Re: Game Scripting

Posted: Sun Jan 20, 2019 3:29 am
by jlv
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.

Re: Game Scripting

Posted: Sun Jan 20, 2019 3:41 am
by jlv
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

Posted: Sun Jan 20, 2019 4:03 am
by wheels1758
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!

Re: Game Scripting

Posted: Sun Jan 20, 2019 5:21 am
by aaronr5
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

Re: Game Scripting

Posted: Mon Jan 21, 2019 11:10 am
by DJ99X
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;
}

Re: Game Scripting

Posted: Mon Jan 21, 2019 12:06 pm
by DJ99X
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;

}

Re: Game Scripting

Posted: Mon Jan 21, 2019 4:47 pm
by AtlasZoor
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...

Re: Game Scripting

Posted: Mon Jan 21, 2019 6:40 pm
by DJ99X
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

Re: Game Scripting

Posted: Mon Jan 21, 2019 7:05 pm
by wheels1758
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?

Re: Game Scripting

Posted: Mon Jan 21, 2019 7:34 pm
by DJ99X
I wasn't sure if that was absolute velocity or not, I didn't try it.