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 4 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.

player = game.Players.LocalPlayer
repeat wait() until player.Character ~= nil
local hum = player.Character.HumanoidRootPart
local mouse = player:GetMouse()
local tweenservice = game:GetService("TweenService")

local function attack()
local direction = hum.CFrame.lookVector * 60
local part = game.ReplicatedStorage.Water:Clone()
    part.Parent = workspace
    part.CanCollide = false
    part.Velocity = direction
    part.CFrame = CFrame.new(0,0,0)
    part.Orientation = Vector3.new(-90,0,0)
    part.Position = hum.Position + Vector3.new(0,-.5,0)
local bf = Instance.new("BodyForce")
 bf.Force = Vector3.new(0, workspace.Gravity * part:GetMass() * 1, 0)
 bf.Parent = part
wait(0.7)
part:Destroy()
end
mouse.Button1Down:Connect(attack)

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 4 years ago

I think CFrame Has a lookvector property

EXAMPLE

LocalScript

local Char = game.Players.LocalPlayer.Character
local LookVector = Char.HumanoidRootPart.CFrame.LookVector -This is the lookvector

[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 — 4y
0
Make it so the orientation doesn't change? Luka_Gaming07 534 — 4y
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 — 4y
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 — 4y
0
If it worked Accept the answer Luka_Gaming07 534 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

PartA.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 — 4y
0
This line of code gives me an error "Bad argument #1 to 'new' (Vector3 expected, got CFrame)" Thanks anyways Fl3eandFlo3e 18 — 4y

Answer this question