Jump to content


Photo

Character Vibrating Spontaneously


  • Please log in to reply
1 reply to this topic

#1 Raidation

Raidation

    Java Programmer

  • New Member
  • 341 posts
  • Version:GM8

Posted 27 June 2010 - 01:11 PM

I've barely started on a platform game and I already have bugs, unfortunately.
The problem is, I have a character, a 16x16 block. He jumps around on a bunch of blocks. If he jumps from a high ledge, he starts vibrating in mid air and falls. Then, I'm unable to move him.

My floors are all solids.
Here's the code in the creation event:
<img alt="">xspeed = 0;
yspeed = 0;
xtar = x;
image_speed = 0;

Step Event:
gravity = place_free(x,y+1)*0.5;

x += xspeed;
y += yspeed;
xspeed = 0;
yspeed = 0;

if(keyboard_check(vk_right)) {
if(place_free(xtar+16,y) && x == xtar) {
xtar += 16;
image_index = 0;
}
}
if(keyboard_check(vk_left)) {
if(place_free(xtar-16,y) && x == xtar) {
xtar -= 16;
image_index = 1;
}
}
if(keyboard_check(vk_up)) {
if(place_meeting(x,y+1,o_block)) {
vspeed = -5;
}
}


if(x < xtar) {
xspeed += 4;
}
if(x > xtar) {
xspeed -= 4;
}

Collision with o_block:
move_contact_solid(direction,vspeed);
vspeed = 0;
if(y < other.y-16) {
y = other.y-16;
}

And here's the gmk if you wanted to take a look:
Download Link

This is in GM8 format.

Thanks. :)
  • 0

#2 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 27 June 2010 - 01:37 PM

If he jumps from a high ledge, he starts vibrating in mid air and falls.

Jumping from a high ledge does not do it for me, it looks to be a bit random (by the way : how do you get the player to jump onto that top platform ? :huh:)

The problem is the way you make the block move horizontally, using "xtar". Although you move, at the botom of the code, left or right as long as your players X-position is not equal to "xtar" (and 4 times 4 equals the 16 you change "xtar" with and should thus exactly work) you are forgetting that the gravity also works on the horizontal position.

This causes the players "x" to change a litle bit, but enough to make it impossible to become equal to "xtar" : it oversteps its target, than jumps back, again overstapping, and than it repeats itself.

In other words : you either need to change the gravity to only have an effect on the "vspeed" variable, or you need to change the "xspeed += 4;" and "xspeed -= 4;" lines in such a way that if the player is nearer than 4 pixels to "xtar" he moves only the remaining distance.

Maybe like this :
if(x < xtar) {
  xspeed += min(+4,x-xtar);
}
if(x > xtar) {
  xspeed -= max(-4,x-xtar);
}
Or all in one line :
speed += max(-4, min(+4, xtar-x) )
Hope that helps.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users