trouble with gravity

K

kinguhdahood5

Guest
I'm a bit stuck on a game I've been creating for quite some time now.. I've been able to work around it
but it just gets more irritating as it goes.

So, I've been using the bits of code for this where it gives you the test variables, test collisions, etc. What I did was use the collision question. So it said if there was not a collision with ONLY solids, then gravity = 0.6 with direction = 270. if else the gravity is reset. When I jump, all I do is set the vertical speed to 10.

My problem is that if I create another object, like a box, and I make the object NOT solid, my character still acts as if it is. The result is that the character basically runs in the air until the object and the character aren't colliding anymore, then the character actually plays its jumping motion.

I don't know if there's anymore coding necessary but if you know what I'm doing wrong please help me.
 

jo-thijs

Member
Hi and welcome to the GMC!

The information you've given is insufficient to tell what exactly goes wrong.
Could you provide us the object information of the player object?
 
K

kinguhdahood5

Guest
Hi and thank you. In the step event of my character, I go to the control tab and use the check collision event. So the question is set to ask 'if there is not a collision relative to (0,1) with only solid objects.'
Under that, I use the gravity event in the move tab and I set the gravity to 0.6 with a direction of 270. Then, under the 'else' event, I set the gravity to 0 in the same direction. I don't use relative with the gravity at all.

In the key press 'up' event, I put the check collision event in and ask 'if there is a collision relative to (0,1) with only solid objects.' Under that I use the vertical speed event and set the vertical speed to '-10.'
I have a lot of other coding but no of it else to do with gravity or vertical speed. Most of that is actually typed in code though. I just have trouble typing code with gravity and collision.
 

jo-thijs

Member
I actually was interested in the other code as well, as I thought it might be relevant.
With the object information, I actually meant the text that you get when you click on "object information" when editing an object,
as that gives all the information about the object.
 
K

kinguhdahood5

Guest
Oh ok. sorry about that. Here I'll paste it:

Information about object: userstick2
Sprite: Rstand7
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

view_object = userstick2;

set variable dead to 0
set variable destroy to 0
set variable rage to 0
set variable jumpkick to 0
set variable Rgoing to 0
set variable going to 0
set variable going2 to 0
set variable Ljump to 0
set variable Rjump to 0
set variable still to 0
set variable air to 0
set variable air2 to 0
set variable Rstill to true
set variable Rsprint to 0
set variable Lsprint to 0
set variable Cwall to 0
set variable Rpunch to 0
Step Event:
if relative position (0,1) gives not a collision with Only solid objects
set the gravity to 0.6 in direction 270
else
set the gravity to 0 in direction 270
COMMENT:
if relative position (0,1) gives not a collision with Only solid objects
set variable air to true
else
set variable air to false
COMMENT:
execute code:

if air = true { if keyboard_check_pressed(vk_right) || keyboard_check_pressed(vk_left) {
Cwall = false }};

execute code:

if keyboard_check_pressed(vk_right) { going = true };

if going = true {if keyboard_check(vk_right) { hspeed += 0.5 } else { hspeed = 0}};

if hspeed > 7 { hspeed = 8 going = false {if keyboard_check(vk_right){} else { hspeed = 0 }}};

if keyboard_check_released( vk_right ) { going = false };




execute code:

if keyboard_check_pressed(vk_left) { going2 = true };

if going2 = true {if keyboard_check(vk_left) { hspeed += -0.5 } else { hspeed = 0}};

if hspeed < -7 { hspeed = -8 going2 = false {if keyboard_check(vk_left){} else { hspeed = 0 }}};

if keyboard_check_released( vk_left ) { going2 = false };

execute code:

if instance_exists(cpu1_8){

if userstick2.y < cpu1_8.y { air2 = true } else { air2 = false }
};;
if destroy = true { instance_destroy() };;

COMMENT:
if relative position (0,1) gives a collision with Only solid objects
execute code:

if health <= 0 { dead = true };;

if dead = true { if Rstill = true { instance_create(x,y,Rdie_101)} else { instance_create(x,y,Ldie_102)} instance_destroy()};;


COMMENT:
Collision Event with object topwall_4:
set the vertical speed to 0
execute code:

if Cwall = true {

if keyboard_check(vk_left) { going2 = true } else {
hspeed = 0 };

if keyboard_check(vk_right) { going = true } else {
hspeed = 0 }
Cwall = false };

Collision Event with object rightwall_5:
if relative position (0,1) gives not a collision with Only solid objects
set the horizontal speed to 5
set variable Cwall to true
else
bounce not precisely against solid objects
Collision Event with object bottomwall_6:
set the vertical speed to 2
Collision Event with object leftwall_7:
if relative position (0,1) gives not a collision with Only solid objects
set the horizontal speed to -5
set variable Cwall to true
else
bounce not precisely against solid objects
Collision Event with object def_wall58:
if relative position (0,1) gives not a collision with Only solid objects
set the horizontal speed to -5
set variable Cwall to true
else
bounce not precisely against solid objects
Collision Event with object cpu1_8:
set the health relative to -5
if air2 is equal to false
COMMENT:
if Rstill is equal to true
create instance of object cpu_counter34 at relative position (32,0)
for all cpu_counter34: set the sprite to run_in_48 with subimage 0 and speed 0.8
else
create instance of object cpu_counter40 at relative position (32,0)
for all cpu_counter40: set the sprite to run_in_52 with subimage 0 and speed 0.8
COMMENT:
destroy the instance
Collision Event with object basefloor_0:
set the vertical speed to 0
execute code:

if Cwall = true {

if keyboard_check(vk_left) { going2 = true } else {
hspeed = 0 };

if keyboard_check(vk_right) { going = true } else {
hspeed = 0 }
Cwall = false };

Draw Event:
if air is equal to true
execute code:

if keyboard_check(vk_anykey){
if Rstill = true { draw_sprite(Rjump11,-1,userstick2.x,userstick2.y) } else {
draw_sprite(Ljump12,-1,userstick2.x,userstick2.y)}};

if keyboard_check(vk_nokey) {
if Rstill = true { draw_sprite(Rjump11,-1,userstick2.x,userstick2.y) } else {
draw_sprite(Ljump12,-1,userstick2.x,userstick2.y)}};




execute code:

if keyboard_check(vk_right) { Rstill = true };

if keyboard_check(vk_left) { Rstill = false };

else
execute code:

if keyboard_check(vk_right) || keyboard_check(vk_left) {} else {

if keyboard_check(vk_nokey) || keyboard_check(vk_anykey) {if Rstill = true { draw_sprite(Rstand7,-1,userstick2.x,userstick2.y) } else {
draw_sprite(Lstand10,-1,userstick2.x,userstick2.y)}}
};
if keyboard_check(vk_right) { draw_sprite(Rrun8,-1,userstick2.x,userstick2.y)
} ;
if keyboard_check(vk_left) {draw_sprite(Lrun9,-1,userstick2.x,userstick2.y)
};

execute code:

if keyboard_check(vk_right) { Rstill = true };

if keyboard_check(vk_left) { Rstill = false };

Key Press Event for <Space> Key:
if relative position (0,1) gives a collision with Only solid objects
COMMENT:
for all rage_bar77: if rage is equal to 10
for all cpu1_8: set variable Rstill to true
for all cpu1_8: set variable rage to true
destroy the instance
create instance of object ragestick78 at relative position (0,0)
for all rage_bar77: set variable rage to 0
COMMENT:
Key Press Event for <Up> Key:
if relative position (0,1) gives a collision with Only solid objects
set the vertical speed to -10
Key Press Event for A-key Key:
if relative position (0,1) gives a collision with Only solid objects
COMMENT:
if Rstill is equal to true
create instance of object kick12 at relative position (0,0) with speed 1 in direction 0
for all kick12: set the sprite to Rkick18 with subimage 0 and speed 1
for all kick12: set variable Rstill to true
destroy the instance
else
create instance of object kick12 at relative position (0,0) with speed -1 in direction 0
for all kick12: set the sprite to Lkick19 with subimage 0 and speed 1
for all kick12: set variable Rstill to false
destroy the instance
COMMENT:
COMMENT:
Key Press Event for D-key Key:
if relative position (0,1) gives a collision with Only solid objects
COMMENT:
if Rstill is equal to true
create instance of object punch10 at relative position (0,0) with speed 4 in direction 0
for all punch10: set the sprite to Rpunch14 with subimage 0 and speed 1
for all punch10: set variable Rstill to true
destroy the instance
else
create instance of object punch10 at relative position (0,0) with speed -4 in direction 0
for all punch10: set the sprite to Lpunch15 with subimage 0 and speed 1
for all punch10: set variable Rstill to false
destroy the instance
COMMENT:
COMMENT:
Key Press Event for S-key Key:
if relative position (0,1) gives a collision with Only solid objects
COMMENT:
if Rstill is equal to true
create instance of object counter14 at relative position (0,0)
for all counter14: set the sprite to Rcounter24 with subimage 0 and speed 1
for all counter14: set variable Rstill to true
destroy the instance
else
create instance of object counter14 at relative position (0,0)
for all counter14: set the sprite to Lcounter25 with subimage 0 and speed 1
for all counter14: set variable Rstill to false
destroy the instance
COMMENT:
COMMENT:
Key Press Event for W-key Key:
if relative position (0,1) gives a collision with Only solid objects
COMMENT:
if Rstill is equal to true
create instance of object kick2_13 at relative position (0,0) with speed 3 in direction 0
for all kick2_13: set the sprite to Rkick2_20 with subimage 0 and speed 1
for all kick2_13: set variable Rstill to true
destroy the instance
else
create instance of object kick2_13 at relative position (0,0) with speed -3 in direction 0
for all kick2_13: set the sprite to Lkick2_21 with subimage 0 and speed 1
for all kick2_13: set variable Rstill to false
destroy the instance
COMMENT:
COMMENT:
 

jo-thijs

Member
Ok, that's way more complicated than I thought it would be.
I feel like it would be fastest if you could upload the gmz file of your project (File > Export Project) somewhere and share the link.
 
K

kinguhdahood5

Guest
Alright. Yeah I figured it would be a lot. I exported the project but Idk what to do next. It's in my files do I send the file?
 

jo-thijs

Member
Upload the file to some online storage (mediafire, dropbox, onedrive, google drive, box, ...)
and share the link to it.
 
Top