• 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!

Legacy GM [SOLVED] phy_active spawns extra Physics objects

G

GamingWalrus

Guest
I'm working on a physics game where you try to build a tower by stacking various shoes, but I have a problem. When I hit the "P" key, a physics inactive object spawns, and the player can manipulate it some before pressing the spacebar to activate its physics and cause the shoe to fall. However, when the space key is pressed, the object spawns three more shoes with it, and I don't know why. Can anyone help me with this? Thank you.
 

jo-thijs

Member
Can you give us the object information of the relevant objectds (the spawned object and the object that spawned it)?
 
G

GamingWalrus

Guest
Of course. There is a ground object and a shoe object, both of which are children of an object used for the collision events. Basically, there is an obj_collision, and it is parent to obj_shoe and obj_ground. Since this is a debug build, I put an event in obj_ground where pressing P spawns the shoe right above the ground. When I press the spacebar, the shoe becomes phy_active, which is when the other three shoes spawn. I've noticed this occurs whenever the obj_shoe has a collision event with another instance of obj_shoe, whether with itself or with the parent object. Thanks for helping.
 

jo-thijs

Member
I actually meant the text that shows up when you click on the button "object information" when editing an object.
That way, I can see all the code and settings of the object.
 
G

GamingWalrus

Guest
Mea culpa. Here is the information
.
Information about object: obj_shoe
Sprite: spr_ground
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_sneaker
obj_ground
Mask:
No Physics Object
Create Event:
execute code:

control = true

Collision Event with object obj_shoe:
execute code:

///Collision Code

Information about object: obj_sneaker
Sprite: spr_sneaker
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_shoe
Children:
Mask:
Physics
Start Awake: true
Is Kinematic: false
Is Sensor: false
Density: 0.5
Restitution: 0.1
Group: 0
Linear Damping: 0.1
Angular Damping: 0.1
Friction: 0.2
Shape: Polygon
Points:
(8, 0)
(40, 0)
(88, 12)
(96, 28)
(92, 36)
(4, 36)
(0, 16)
Create Event:
execute code:

phy_active = false
//hspeed = choose(-2,2)

Step Event:
execute code:

if keyboard_check(ord('A')) && !phy_active
{
phy_rotation -= 2
}

if keyboard_check(ord('D')) && !phy_active
{
phy_rotation += 2
}

if keyboard_check_pressed(vk_space) && !phy_active
{
phy_active = true
}

Other Event: Outside Room:
execute code:

instance_destroy();

Information about object: obj_ground
Sprite: spr_ground
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_shoe
Children:
Mask:
Physics
Start Awake: true
Is Kinematic: false
Is Sensor: false
Density: 0
Restitution: 0.1
Group: 0
Linear Damping: 0.1
Angular Damping: 0.1
Friction: 0.2
Shape: Box
Points:
(0, 0)
(64, 0)
(64, 64)
(0, 64)
Create Event:
execute code:

///Placeholder

Key Press Event for P-key Key:
execute code:

instance_create(room_width/2,96,obj_sneaker)

I apologize if this isn't the most clean, this is really just a debug build to see if it works as a concept or not.
 
Last edited by a moderator:
G

GamingWalrus

Guest
The obj_ground information missed a parentheses at the end, but otherwise they were all complete.
 

jo-thijs

Member
Oh, I see, you've got an empty collision event.
How many instances of type obj_ground do you have in the room?
Check this with instance_number(obj_ground) in a create event.
 
G

GamingWalrus

Guest
Now I see the problem. I had multiple instances to create a larger base. D'oh. Thanks for helping me solve the problem!
 
Top