Edited by Emd, 13 April 2012 - 07:27 PM.
Platform enemy gravity
Started by Emd, Apr 13 2012 07:20 PM
4 replies to this topic
#1
Posted 13 April 2012 - 07:20 PM
I have an enemy in a platform game that turns if it crashes with a wall. I put gravity on it, but it doesn't work.
#2
Posted 13 April 2012 - 07:46 PM
I have an enemy in a platform game that turns if it crashes with a wall. I put gravity on it, but it doesn't work.
That's very interesting, but not very informative. What have you tried specifically? We're going to need some more detail (such as the D&D or code you have used in the object related to the gravity) to be able to help you
#3
Posted 13 April 2012 - 09:31 PM
Create event:
hspeed = 2
Step event:
if place_free(x,y+1)
{
gravity_direction=270
gravity=0.5
}
else
{
gravity_direction=270
gravity=0
}
if hspeed > 0
{
image_xscale = -1
}
else
{
image_xscale = 1
}
Collision event with wall:
move_contact_solid(direction,12)
Collision event with marker:
if hspeed = 2
{
hspeed = -2
}
else
{
hspeed = 2
}
hspeed = 2
Step event:
if place_free(x,y+1)
{
gravity_direction=270
gravity=0.5
}
else
{
gravity_direction=270
gravity=0
}
if hspeed > 0
{
image_xscale = -1
}
else
{
image_xscale = 1
}
Collision event with wall:
move_contact_solid(direction,12)
Collision event with marker:
if hspeed = 2
{
hspeed = -2
}
else
{
hspeed = 2
}
#4
Posted 13 April 2012 - 09:37 PM
Ok, so what actually isn't working? Is the enemy not falling at all, or is it falling and then getting stuck? It looks like it may be getting stuck, as at no point are you setting the objects vspeed to 0. Basically, when the enemy is falling and collides with the wall underneath it, the collision event moves the object back to its former x,y position, and then executes any code within the collision event. So at the moment, you are only moving the object into contact with the wall, and because its vspeed will still be greater than 0, the collision will occur again the following step. Try adding the line:
Into the collision event, just underneath the move_contact_solid function.
vspeed=0;
Into the collision event, just underneath the move_contact_solid function.
#5
Posted 13 April 2012 - 09:43 PM
Thanks, it works perfectly!!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











