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

How do I make a projectile face the same way as the player?

Asked by 5 years ago

So far i made it so that you can attack with a button1down function but I cant make it so the projectile that is spawned faces the same way as the player without changing the orientation.

01player = game.Players.LocalPlayer
02repeat wait() until player.Character ~= nil
03local hum = player.Character.HumanoidRootPart
04local mouse = player:GetMouse()
05local tweenservice = game:GetService("TweenService")
06 
07local function attack()
08local direction = hum.CFrame.lookVector * 60
09local part = game.ReplicatedStorage.Water:Clone()
10    part.Parent = workspace
11    part.CanCollide = false
12    part.Velocity = direction
13    part.CFrame = CFrame.new(0,0,0)
14    part.Orientation = Vector3.new(-90,0,0)
15    part.Position = hum.Position + Vector3.new(0,-.5,0)
View all 22 lines...

I did manage to change the orientation but when I do that the projectile doesn't shoot from the player. Any suggestions?

2 answers

Log in to vote
0
Answered by 5 years ago

I think CFrame Has a lookvector property

EXAMPLE

LocalScript

1local Char = game.Players.LocalPlayer.Character
2local LookVector = Char.HumanoidRootPart.CFrame.LookVector -This is the lookvector
3 
4[Projectile].CFrame = CFrame.new([Projectile].Position, Vector3.new(LookVector))

The wiki is down today soo :/ I'M NOT SURE

0
Yea I've already used this method, what ends up happening is that part faces the same direction but the orientation changes so the projectile looks akward. Fl3eandFlo3e 18 — 5y
0
Make it so the orientation doesn't change? Luka_Gaming07 534 — 5y
0
Im not sure how to make the orientation stay the same, they way i did it it made the part face only one direction while the player faced another way. Fl3eandFlo3e 18 — 5y
0
Ok it worked! I dont know why it didnt work the last time but now it does, the only problem is once i move the part immediately shifts its orientation. Fl3eandFlo3e 18 — 5y
0
If it worked Accept the answer Luka_Gaming07 534 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You can use this piece of code to face one part to another.

1PartA.CFrame = CFrame.new(PartA.Position, PartB.Position)

The second argument of a CFrame is were the CFrame should face, the input is a Vector3 value.

0
he wants it to face the same way as the player, not to face the player theking48989987 2147 — 5y
0
This line of code gives me an error "Bad argument #1 to 'new' (Vector3 expected, got CFrame)" Thanks anyways Fl3eandFlo3e 18 — 5y

Answer this question