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

How do i make it so that a model is only visible when the player stands on front of it?

Asked by 4 years ago

im making a non euclidean game and im having difficulty of how to do this. any effort is ok as long as i can do this.

0
maybe create a region3 area in front of the NPC? Spiritlotus 151 — 4y
0
Have you tried making a extra part and using touch functions? GD_Bluey -5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Keep in mind, this is what i interpret as the easiest method.

Calculating The FOV of the model. this may seem confusing.

NEW TOPICS

Vector3.Unit CFrame.LookVector

UNIT

A vector represents a direction and magnitude (length).

You can think of a vector as an arrow pointing in a certain direction that also has a length, in this case 2 units.

A unit vector is a vector that has a direction and a length of 1 unit, meaning that it only indicates direction

LookVector.

LookVector is a property of CFrames aka Coordinate Frames that represent the unit vector of the CFrame direction. If you’d like to construct your own CFrames with lookvectors, you can call CFrame.fromMatrix.

1CFrame.fromMatrix ( Vector3 14 pos, Vector3 14 vX, Vector3 14 vY, Vector3 14 vZ )

Creates a CFrame from a translation and the columns of a rotation matrix. If vz is excluded, the third column is calculated as [vx:Cross(vy).Unit].

This example uses CFrame.fromMatrix() to create a CFrame located at eye with it’s lookVector pointing towards the target position.

1function lookAt(target, eye)
2    local forwardVector = (eye - target).Unit
3    local upVector = Vector3.new(0, 1, 0)
4    -- You have to remember the right hand rule or google search to get this right
5    local rightVector = forwardVector:Cross(upVector)
6    local upVector2 = rightVector:Cross(forwardVector)
7    return CFrame.fromMatrix(eye, rightVector, upVector2)
8end

A more simple explanation;

Look/Up/Right Vectors describe the direction of the Front/Top/Right faces.

Your script

Make a Local Script in StarterCharacterScripts Give the model a primarypart.

01local Player = game.Players.LocalPlayer
02local RunService = game:GetService("RunService")
03 
04local ModelName = "" -- name of your model
05local Model = workspace[ModelName]
06 
07wait(3)
08 
09local Character = Player.Character
10local found = false
11 
12 
13local TweenService = game:GetService("TweenService")
14 
15function checkDist(part1, part2)
View all 58 lines...
Ad

Answer this question