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

How do I make a brick spawn in front of me?

Asked by 9 years ago

I am trying to make a script that spawns a brick in front of me but I have no idea how xD

This is the best I can come up with

a = Instance.new("Part", workspace)
a.Anchored = true
a.Position = game.Players.LocalPlayer.Character.Torso.Position

But that spawns it at my Torsos position I want it to spawn in front of me

Thanks

0
You need to add 1 to the Z or X Vector. Get the position of the Torso, and then add 1 vector to X or Z KordGamer 155 — 9y
0
Could you try to script an example for me xD silverminer226 4 — 9y

2 answers

Log in to vote
3
Answered by
Fubl 15
9 years ago

In essence, you are asking how to find a location in front of a part, then place a part there. Sigive10's answer is incorrect, as the front of something is relative to the object, not world coordinates which his example provides.

First, you'll want to place your part where your torso is, so:

Brick.Position = Torso.Position

Next, you'll want to get the direction your Torso is pointing. Otherwise, it wouldn't be 5 studs in front of the Torso, but rather exactly where the Torso is located. Thankfully, Roblox provides a very easy way to do this: the CFrame property lookVector, which returns a vector pointing forward from the front face of any CFrame.

We add this vector to the Brick's position:

Brick.Position = Torso.Position + Torso.CFrame.lookVector

As lookVector is a unit vector, it is one stud 'long' in simple terms, thus to get it to 5 studs in length, we can mutiply it by 5:

Brick.Position = Torso.Position + Torso.CFrame.lookVector * 5

And there we are, you have a brick 5 studs in front of the torso.

Ad
Log in to vote
-3
Answered by
sigve10 94
9 years ago

Here you go

a = Instance.new("Part", workspace)
a.Anchored = true
a.Position = game.Players.LocalPlayer.Character.Torso.Position + Vector3.new(0,0,-5)

There ya go. You just have to add the Vector3 that you want to the Vector3 that you have. In that way it spawns a Vector3 amount of offset from the character

Answer this question