• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Swing Physics code broke after 2.3 update.

S

Sonicspirit4ever

Guest
I've read the release notes on the Gms2.3 update and it seems like nothing (that should effect my code) has been changed. I'm making a sonic game and I programmed a swing to move sonic accordingly when it's in motion. The code was fine till after the update. Sonic will move along in the correct y-axis, but moves in the negative x motion. I've tried simply putting a "-" before the same code and it hasn't worked. I've also tried using the y-axis coding and switching the "sin" to "cos", no luck. I'm kinda getting frustrated cuz I don't really have time for these errors since I'm on a deadline, but I could really use that new sequencing resource for a new start screen animation (among many other things.)

Any help is much appreciated, and please tell if more information is required.


All the code in the object is pasted below
// Create Event

/// @description Insert description here
// You can write your code in this editor
scr_create()
on_screen = off
// Radius lengths
chain[1] = 128;
chain[2] = 192;
chain[3] = 256;
chain[4] = 384;
chain[5] = 448;

scr_timer(0,5)
scr_timer(1,5)

// Movement Vars
radius = chain[2];

// Angle Variables
angle_right_limit = 340;
angle_left_limit = 200;
center_point = 270;
angle = angle_left_limit;

// Swing Variables
depth = 0; // Depth
vsp = 0; // Speed of swing
swing_rate = -0.8; // Swing kick
grav_force = 0 // gravity applied forces
left = -1 // Direct var
right = 1 // Direct var
move_direct = left; // Direction

// The gravity and speed work together. Multiply each set by 2 for faster results
grav = 0.03
spd_lmt = 2.5



// Collision
dif_x = 0;
dif_y = 0;

created = 0
/*
if radius == chain[0]
{
cord = obj_chain_0;
}
else if radius == chain[1]
{
cord = obj_chain_1;
}
else if radius == chain[2]
{
cord = obj_chain_2;
}
else if radius == chain[3]
{
cord = obj_chain_3;
}


xpos = lengthdir_x(radius,angle);
ypos = lengthdir_y(radius,angle);

near_plat = instance_create_depth(x+xpos,y+ypos,5,obj_swingplt);
chain_link = instance_create_depth(x,y,5,cord)
chain_link.image_angle = angle


// Step Event

/// @description Insert description here
// You can write your code in this editor
var ALL = angle_left_limit
var ARL = angle_right_limit
var cp = center_point
if created == 0
{
if radius == chain[0]
{
cord = obj_chain_0;
}
else if radius == chain[1]
{
cord = obj_chain_1;
}
else if radius == chain[2]
{
cord = obj_chain_2;
}
else if radius == chain[3]
{
cord = obj_chain_3;
}


xpos = lengthdir_x(radius,angle);
ypos = lengthdir_y(radius,angle);

near_plat = instance_create_depth(x+xpos,y+ypos,5,obj_swingplt);
chain_link = instance_create_depth(x,y,5,cord)
chain_link.image_angle = angle

created+= 1
}


if global.pause == off
{
// Point of Equilibrium
if angle == cp
{
grav_force = 0
}
// apply Negative Gravity
if angle > cp
{
grav_force = grav
vsp-= grav_force
}
if angle < cp
{
grav_force = grav
vsp+= grav_force
}
if grav_force == 0
{
if move_direct == left && angle > ALL
{
if vsp >= -spd_lmt vsp-= abs(swing_rate)
}
if move_direct == right && angle < ARL
{
if vsp <= spd_lmt vsp+= abs(swing_rate)
}
}
if angle <= ALL || (floor(abs(vsp)) == 0 && angle < cp)
{
move_direct = right
}
if angle >= ARL || (floor(abs(vsp)) == 0 && angle > cp)
{
move_direct = left
}
// Clamp
if vsp > spd_lmt vsp = spd_lmt;
if vsp < -spd_lmt vsp = -spd_lmt;


angle+= vsp

chain_link.image_angle = angle
}
near_plat.x = x+lengthdir_x(radius,angle);
near_plat.y = y+lengthdir_y(radius,angle);

// End Step Event

/// @description Insert description here
// You can write your code in this editor
var rate = vsp
var sonic = Player
var swing = obj_swing
with(near_plat) // Near_plat is the id used for the board sonic is on.
{
var dif_x = floor(x)-floor(xprevious)
if sonic.action != sonic.act_death
{
if place_meeting(x,y-1,sonic) && solid == 1
{
if solid == 1
{
sonic.x+= dif_x
sonic.y-= (-1*sin(swing.angle)*rate)/swing.radius
}
}
}
}

Any help is much appreciated.
 

Attachments

obscene

Member
Please use [ code ] [ / code ] tags when putting code on the forums, it makes it easier to read.

My guess is it's related to your lack of use of semicolons, especially after var declarations. A lot of random things can go wrong when you skip out on those specifically. Wouldn't hurt to get in the practice of using parenthesis where needed too...

Code:
var variable=1;
if (variable==1)
 { 
 do stuff;
 }
 
Top