Mouse Click Object (Not working)

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    I've got a player sprite with a few variable on it, and an action I'd like fire if the user clicks on the enemyUnit. The problem is the left clicks are only registering if I click on the canvas. I'm not sure why this isn't working. Every single condition is met. Can someone tell me why it's not working? I really don't know. I've checked the other actions. I don't see where another action might be firing to mess this up. Any tips.

    Thank too. Just frustrated. There's unanswered posts, and not the first thing that's tripped me up, but might be my fault Thanks guys.

    My action conditions

    on left button clicked on enemyUnit

    cursor is over enemyUnit

    playerUnit isTurn

    playerUnit isFiring

    not playerUnit hasFired

    player unit has line of site to enemyUnit.X, enemyUnit.Y

    Action

    playerUnit set mouseX to Mouse.X

    playerUnit set mouseY to Mouse.Y

    set destAngleX to enemyUnit.X

    set destAngleY to enemyUnit.Y

    set destAngleSet to true

    set rotateToDestAngle to true

    Debug readout on playerUnit

    isTurn 1

    isMoving 0

    mouseX 691.830985915493

    mouseY 58.59154929577465

    hasFired 0

    isFiring 1

    destAngleX 693.2717046230803

    rotateToDestAngle 1

    destAngleY 59.32356140793535

    destAngleSet 1

    Line of site for the playerUnit is 120px

  • I've solved this. For some reason solid behavior was interfering with the mouse click. Not sure if this is a bug or not.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • JeremyBenson11 I doubt it is a bug in C2 - probably factored into line of sight, or maybe it was stopping the projectile. There is almost always an explanation - sometimes finding the reason can be difficult (and frustrating).

  • I just told you what the fix was. I removed solid, and it worked. It wasn't line of sight. I could be 5px away and it wouldn't click. Removed solid and it worked like a charm.

  • JeremyBenson11 - well, I was just telling you it is not a bug in C2. The Line of sight behavior uses Solids as obstacles (unless you use custom obstacles). Since your object had the solid behavior, it was considered an obstacle, and therefore your player did not have line of sight to it. That is why the click did not work - not because there is a bug with mouse clicks on solid objects, but because your player did not "see" the object even if it was 5px away. (the "player unit has line of site to enemyUnit.X, enemyUnit.Y" was false, and that stopped the code from executing).

    removing the solid behavior was the correct fix, but the issue was the conflict between trying to see something that was obstructed, not because of a bug with mouse clicks in C2. (although, you could argue that line of sight should be able to "see" the obstructions - unless they are obstructed by something else. but that would be a feature to request)

  • Ah. I see what you're saying. More of a design issue than anything. Thanks for the info.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)