Detect where is the player looking at and change cursor

For questions about using Classic.

Post » Mon Feb 14, 2011 1:36 pm

Hi there.

I'd like to ask: is there some kind of way to detect where is the player looking at?

Imagine it's a birdseye shooter. The mouse movement changes the player's angle. If the player looks at a sprite, a text message would appear. Kind of like in HL2: EP. 1 (or 2, I don't remember), where we look outside a window and a monster spawns behind us.

Also, I'd like to know if there's any way to change the cursor to a crosshair, but only in-game.

Thanks in advance,
velosotiago
B
4
S
1
G
2
Posts: 75
Reputation: 1,000

Post » Mon Feb 14, 2011 3:42 pm

You can add to the player the Line of Sight behaviour.

And as for the cursor, add the "mouse and keyboard" object. Then, in the events, add:
-Start of Layout : set cursor invisible;

Make the crosshair sprite and give it the mouse behaviour. This should make that sprite follow the hidden cursor.

Tip: you can even give that sprite some animations, so when the player shoot, the crosshair changes.
B
50
S
16
G
7
Posts: 59
Reputation: 6,365

Post » Mon Feb 14, 2011 5:39 pm

Nice! I'll try both and post how it went later.

Btw, is there any way to make it so the mouse can't go out of the game window except when in pause? (being ESC the pause key, if that helps)

Thanks in advance,
velosotiago

EDIT: Both work like a charm! Thanks alot!
B
4
S
1
G
2
Posts: 75
Reputation: 1,000

Post » Tue Feb 15, 2011 5:37 pm

BUMP

Can someone answer the question I asked in the last post?

Thanks in advance,
velosotiago
B
4
S
1
G
2
Posts: 75
Reputation: 1,000

Post » Tue Feb 15, 2011 6:40 pm

I'll let you figure out how to do a state when in pause.

Mouse set x to clamp(mousex,0,displaywidth)
Mouse set y to clamp(mousey,0,displayheight)

You'll want to add some way to exit the program, as you cant get to the close button in the frame, and esc is the standard for exiting via keyboard.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Feb 15, 2011 7:14 pm

Yeah, I'd make a Exit to Menu button in the pause menu.

(a 'Exit' button would be useless because when in the pause menu the mouse would be able to go out of the window...)
B
4
S
1
G
2
Posts: 75
Reputation: 1,000


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests