Jump to content


Photo

Platform Enemy Won't Do His Job!


  • Please log in to reply
3 replies to this topic

#1 LOLZ97

LOLZ97

    GMC Member

  • GMC Member
  • 115 posts

Posted 18 September 2011 - 01:27 AM

Hey, I'm making a platformer... and this enemy I made is supposed to just go back and forth in an area, but when the character get close enough, he will follow him. If the character get out of range, he will go back to his pacing. Here are my codes for the enemy:
Step
if place_free(x,y+1) {
gravity = 1
}
else{
gravity = 0
}
gravity_direction = 270
if distance_to_object(o_Player) < 100 {
if o_Player > x {
char = 1
}
if o_Player < x {
char = 0
}
maxspeed = 6
}
else {
maxspeed = 4
}
if char = 1 {
hspeed = maxspeed
sprite_index = s_EnemyR
}
if char = 0 {
hspeed = -maxspeed
sprite_index = s_EnemyL
}
image_speed = maxspeed/4
if !place_free(x+16,y) {
hspeed = -hspeed
}
if !place_free(x-16,y) {
hspeed = -hspeed
}
Create
maxspeed = 4
char = 1
and Collision with o_Solid
move_contact_solid(direction,vspeed)
vspeed = 0
Please help meh?!?!?

Edited by LOLZ97, 18 September 2011 - 01:30 AM.

  • 0

#2 Gangsterman

Gangsterman

    GMC Member

  • GMC Member
  • 35 posts

Posted 18 September 2011 - 03:58 AM

Hey, I'm making a platformer... and this enemy I made is supposed to just go back and forth in an area, but when the character get close enough, he will follow him. If the character get out of range, he will go back to his pacing. Here are my codes for the enemy:
Step

if place_free(x,y+1) {
gravity = 1
}
else{
gravity = 0
}
gravity_direction = 270
if distance_to_object(o_Player) < 100 {
if o_Player > x {
char = 1
}
if o_Player < x {
char = 0
}
maxspeed = 6
}
else {
maxspeed = 4
}
if char = 1 {
hspeed = maxspeed
sprite_index = s_EnemyR
}
if char = 0 {
hspeed = -maxspeed
sprite_index = s_EnemyL
}
image_speed = maxspeed/4
if !place_free(x+16,y) {
hspeed = -hspeed
}
if !place_free(x-16,y) {
hspeed = -hspeed
}
Create
maxspeed = 4
char = 1
and Collision with o_Solid
move_contact_solid(direction,vspeed)
vspeed = 0
Please help meh?!?!?


idk,replace char because it might be a constance
something like chase=1
  • 0

#3 LOLZ97

LOLZ97

    GMC Member

  • GMC Member
  • 115 posts

Posted 18 September 2011 - 04:10 AM


Hey, I'm making a platformer... and this enemy I made is supposed to just go back and forth in an area, but when the character get close enough, he will follow him. If the character get out of range, he will go back to his pacing. Here are my codes for the enemy:
Step

if place_free(x,y+1) {
gravity = 1
}
else{
gravity = 0
}
gravity_direction = 270
if distance_to_object(o_Player) < 100 {
if o_Player > x {
char = 1
}
if o_Player < x {
char = 0
}
maxspeed = 6
}
else {
maxspeed = 4
}
if char = 1 {
hspeed = maxspeed
sprite_index = s_EnemyR
}
if char = 0 {
hspeed = -maxspeed
sprite_index = s_EnemyL
}
image_speed = maxspeed/4
if !place_free(x+16,y) {
hspeed = -hspeed
}
if !place_free(x-16,y) {
hspeed = -hspeed
}
Create
maxspeed = 4
char = 1
and Collision with o_Solid
move_contact_solid(direction,vspeed)
vspeed = 0
Please help meh?!?!?


idk,replace char because it might be a constance
something like chase=1

am using it in the character, and he's perfectly fine. Plus i've used it many times before!

I
  • 0

#4 Richard

Richard

    Retired Staff

  • Retired Staff
  • 1258 posts

Posted 18 September 2011 - 07:12 AM

if o_Player > x {
char = 1
}
if o_Player < x {
char = 0
}

I assume o_Player is the name of the player object resource? This code tries to compare that object resource name to the enemy's x coordinate, which doesn't make sense! Game Maker does internally give each resource a number, so as far as it is concerned it is acceptable to compare that to a numerical x coordinate and that is why you don't get an error - but I imagine you actually intended to compare the enemy's x coordinate to that of the player.

You could use o_Player.x to refer to the player's x coordinate, but only as long as you only ever use one single instance of the player object. If you do sometimes use more than one for any reason you'll need to use the instance ID of the specific player instance whose x coordinate you need to refer to.

Hope that helps.

Richard
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users