Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the center of the screen as Vector3 without the help of a mouse? [SOLVED]

Asked by 4 years ago
Edited 4 years ago

I am trying to make a mobile shooter, but the issue is the bullets are going in the direction of the mouse (as for PC), but I don't want it to be happen for mobile users as their mouse can't be locked in the center. Currently, I use :

local pos = (mouse.Hit.p - firepart.Position).Unit

Can I get to know any better version, in which bullets can go to center of the screen and not follow the mouse.

Any help would be appreciated!

2 answers

Log in to vote
0
Answered by 4 years ago

I managed to solved the issue by myself, using lookVector.

Ad
Log in to vote
0
Answered by 4 years ago

Try using a ViewportPointToRay/ScreenPointToRay: ViewportPointToRay You can easily use these to get the center of the camera and fire your rays from the center of that.

I used this in the past to create a nifty highlighter that fires a ray from the camera and uses the player's position to check distance. What I ended up with was a highlighter that can highlight anything the player can see that isn't tied to the viewpoint angle of the player's character (imagine a player zooming out their camera then trying to highlight an object behind another one).

If you do this, then just know if a player zooms their camera out and fires, they can potentially hit something behind cover. To solve this problem, make sure the camera is locked in place (no zooming in or out): CameraMaxZoomDistance

0
I didn't really have to prevent zooming when I created the highlighter since it wasn't a shooter. What I discussed is probably the whole reason why pvp shooters usually have a locked camera distance. SteelMettle1 394 — 4y

Answer this question