Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

5 comments

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.

0

Make it so the orientation doesn't change?

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.

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.

0

If it worked Accept the answer

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.

2 comments

0

he wants it to face the same way as the player, not to face the player

0

This line of code gives me an error "Bad argument #1 to 'new' (Vector3 expected, got CFrame)" Thanks anyways

This discussion is preserved as it was. New answers, comments, and votes are closed.