Crosshair and player turning

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Crosshair and player turning

Post by Apeirogon »

How make crosshair move in some area on screen, if player move mouse, before actualy turn player?

If I badly explained what I want, heres a picture.
HRODA6A4.gif
Crosshair should be inside red circle(maybe not so large) all time, and must move freely inside this circle. Crosshair still constrolled by mouse/joystick "mushroom"/touchpad/etc.
Optionaly, change direction of shoot bullets, so they fly in direction where crosshair aim, but I think I can found workaround for this.

But player must and should turn only if crosshair try to go out of bound of this red circle. Like, if crosshair tries to go beyond the most upper borders of circle - player camera turns up, most left border - turn left, down border - turn down, south-west border - turn in south-west direction, etc.

I remember I see something like this before, but it was made using acs script, and I need zscript version.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Crosshair and player turning

Post by Apeirogon »

I found video, but as I said, its on acs.
https://www.youtube.com/watch?v=ZB3Gj7CGjF8
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Crosshair and player turning

Post by Matt »

The term I think is "aiming dead zone".

It can be done, but it does mess with player movement prediction so it might not look good in multiplayer.


First, you need to study MovePlayer() and CheckPitch() to figure out what you need to replace.

(basically you need to modify them so they only turn the player after a certain threshold, but still receive input for turning)

Then you need to replace the player pawn to add variables storing the position of the cursor.

Then you need to replace the status bar, and have the crosshair be drawn where the cursor should be. (I don't know how to draw the crosshair; worst case senario you can just draw your own cursor image)
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Crosshair and player turning

Post by Apeirogon »

from check pitch

// The player's view pitch is clamped between -32 and +56 degrees,
// which translates to about half a screen height up and (more than)
// one full screen height down from straight ahead when view panning
// is used.
What?
positions of cursor
You mean ui process event? Or input process?

And why I must use status bar, if there are render overlay?
Or just even create dumy actor with crosshair spite, which float around player.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Crosshair and player turning

Post by Matt »

Oh, right, you want to do it through an overlay.

I'd really rather not touch those since I have no idea how the various types of offsets interact...
Post Reply

Return to “Scripting”