[solved]Collision Circle not registering right

W

Wild_West

Guest
Okay so this is the nice sphere I get when I use thsses values to make one around my attacking player 100x100 sprite dimensions.

Code:
if not(attacking){ exit; }
else
//when you collide with the enemy
if(image_xscale == 1)
and(attacking == true)
and( collision_circle(x+sprite_width/2, y, 100, enemy_targeted, false, true) )
{ hspeed = -20; vspeed = -15;  recoil = true;

if(image_xscale == -1)
and(attacking == true)
and( collision_circle(x-sprite_width-50, y, 100, enemy_targeted, false, true) )
{ hspeed = 20; vspeed = -15;   recoil = true;
As you can see I needed different values for which way the player is facing but I used these for drawing the sphere first and those are the only ones that got it looking right and centered around the character so I repeated them for the collision with enemy detection.
But there's this problem that keeps coming up when I USE the attack to hit enemies, sometimes the hits don't seem to register right because the sprite change for recoil after attacking doesn't happen or with a spinning enemy I have the player goes into his taking damage code instead of hitting the enemy effect code.

I haven't had any trouble using collision shapes except for trying to stop the player leaving a collision rectangle that an enemy creates but, issue for another day.
Can anybody tell me why this collision circle seems to be getting ignored randomly when I try to use it?

Here's what's supposed to happen to some enemies or objects that the player collides with while attacking is true
Code:
if(other.attacking){ vspeed = 30;}
else
{
   with(other)
   {
      move_contact_all(direction, hspeed);
      hspeed = 0;
      x = xprevious;
      vspeed = 5;
   }
}
 
W

Wild_West

Guest
Is the circle's sprite origin centered?
It's not actually a sprite it's just the check for a targeted enemy inside the collision circle.
I could just use a sprite for the collision check though. It's just I started getting comfy with cillision_circe / rectangle / line functions so I figured this would be fine for attacking.
All my others are centered though, save for like background sprites for ease of drawing to the screen.
 
F

FabioF

Guest
try this:

Code:
if not(attacking){ exit; }

//when you collide with the enemy
if(image_xscale == 1)
and(attacking == true)
and( collision_circle(x+sprite_width/2, y, 100, enemy_targeted, false, true) )
{ hspeed = -20; vspeed = -15;  recoil = true;
}else
if(image_xscale == -1)
and(attacking == true)
and( collision_circle(x-sprite_width-50, y, 100, enemy_targeted, false, true) )
{ hspeed = 20; vspeed = -15;   recoil = true;}
 
W

Wild_West

Guest
try this:

Code:
if not(attacking){ exit; }

//when you collide with the enemy
if(image_xscale == 1)
and(attacking == true)
and( collision_circle(x+sprite_width/2, y, 100, enemy_targeted, false, true) )
{ hspeed = -20; vspeed = -15;  recoil = true;
}else
if(image_xscale == -1)
and(attacking == true)
and( collision_circle(x-sprite_width-50, y, 100, enemy_targeted, false, true) )
{ hspeed = 20; vspeed = -15;   recoil = true;}
Hmm, I dunno that it's just having to add the else I mean the conditions can't ever overlap because it's based off the image xscale, and that can't be 1 and -1 at the same time.
 
W

wagyu_so_gud

Guest
instead of writing repeating code based on image_xscale, you could do something like :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
//execute this code in the event that the coll_circle is true;
}
the (sign) will make the final value either a pos/neg based on image_xscale and then it is multiplied by the xoffset var or whatever you define. That doesn't address the issue you're having but I couldn't quite point you in the right direction without seeing what it's doing. I will note that if the var recoil being true runs a code, your statement should include recoil check :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
     if (attacking) && (!recoil)
     {
     hspeed = sign(image_xscale)*20;
     vspeed = -15;
     recoil = true;
     }
}
 
Last edited by a moderator:
W

Wild_West

Guest
instead of writing repeating code based on image_xscale, you could do something like :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
//execute this code in the event that the coll_circle is true;
}
the (sign) will make the final value either a pos/neg based on image_xscale and then it is multiplied by the xoffset var or whatever you define. That doesn't address the issue you're having but I couldn't quite point you in the right direction without seeing what it's doing. I will note that if the var recoil being true runs a code, your statement should include recoil check :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
     if (attacking) && (!recoil)
     {
     hspeed = sign(image_xscale)*20;
     vspeed = -15;
     recoil = true;
     }
}
Yeah the recoil var just sets the player sprite to his spinning animation as he bounces off the enemies he attacks. animation ends and he stops spinning and just goes back to hover sprite in midair or standing if he hits the ground. You can basically keep attacking if you hold the jump key to hover for a while and press the attack key again when near any enemy. attacking is mostly just to make enemies stop shooting for a while so you can destroy their shields and shoot them.

The recoil and sprite changes all works great but the actual code that should be run as a result of being hit in enemies doesn't ALWAYS work, but more often than not it will, except for this one enemy that has a spinning animation. I only ever get hurt by touching it, which if attacking is true shouldn't happen.

If you've ever seen sonic games it's meant to work like his homing attack.
 
W

Wild_West

Guest
instead of writing repeating code based on image_xscale, you could do something like :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
//execute this code in the event that the coll_circle is true;
}
the (sign) will make the final value either a pos/neg based on image_xscale and then it is multiplied by the xoffset var or whatever you define. That doesn't address the issue you're having but I couldn't quite point you in the right direction without seeing what it's doing. I will note that if the var recoil being true runs a code, your statement should include recoil check :

Code:
var xoffset = sprite_get_xoffset(sprite_index);

var coll_circle = collision_circle(x+(sign(image_xscale)*xoffset),y,100,enemy_tageted,0,1);

if (coll_circle != noone)
{
     if (attacking) && (!recoil)
     {
     hspeed = sign(image_xscale)*20;
     vspeed = -15;
     recoil = true;
     }
}
Okay so I had to tweak it a bit just to compensate for a few other parts of the gameplay but your suggestion did help me fix the problem, so you have my thanks.
 
Top