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

[SOLVED] Help with physics code

B

bluGecko

Guest
Hi,

My current project consists of a game set in space. Originally I was just using GameMaker's default system for movement of the player and enemies. I would now like to switch to using physics (Box2d) as this will provide a more 'floaty' feeling to the movement and much more desirable collisions, which is the effect I am looking for. So far I have managed to convert most of my code to now work with physics.

All I'm left with is this code:
Code:
speed = 1 + random(2);
direction = random(4) * 90;
image_angle = direction
alarm_set(0, 100 + random(200));
This code is placed in an Alarm[0] event and is called in the create event.

My question is, how can I get this code to work within the physics engine of GameMaker.

Thank you
 

Jezla

Member
Apply a local impulse to the object in your alarm event.

Code:
var ximpulse = random(90);
var yimpulse = random(90);

physics_apply_local_impulse(0,0, ximpulse, yimpulse);
 
B

bluGecko

Guest
Apply a local impulse to the object in your alarm event.

Code:
var ximpulse = random(90);
var yimpulse = random(90);

physics_apply_local_impulse(0,0, ximpulse, yimpulse);
Hi, I tried your code, but it seems the NPC objects just move in spurts towards the bottom right corner.
 

Jezla

Member
My code was meant as an example. You'll want to adjust how you randomize the ximpulse and yimpulse parameters.
 
B

bluGecko

Guest
My code was meant as an example. You'll want to adjust how you randomize the ximpulse and yimpulse parameters.
Hi, after playing around with your code, and using some other methods, I was able to solve the issue.

Thank you
 
Top