Mouse Click Object (Not working)

Get help using Construct 2

Post » Sun Aug 30, 2015 1:05 am

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
B
7
S
2
Posts: 92
Reputation: 663

Post » Sun Aug 30, 2015 1:41 am

I've solved this. For some reason solid behavior was interfering with the mouse click. Not sure if this is a bug or not.
B
7
S
2
Posts: 92
Reputation: 663

Post » Sun Aug 30, 2015 2:13 am

@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).
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Sun Aug 30, 2015 1:13 pm

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.
B
7
S
2
Posts: 92
Reputation: 663

Post » Sun Aug 30, 2015 3:15 pm

@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)
B
99
S
35
G
20
Posts: 438
Reputation: 17,910

Post » Sun Aug 30, 2015 6:50 pm

Ah. I see what you're saying. More of a design issue than anything. Thanks for the info.
B
7
S
2
Posts: 92
Reputation: 663


Return to How do I....?

Who is online

Users browsing this forum: babymumu and 7 guests