Hi, I’m working on a gun system (which works almost fine), the projectiles shoot in the direction of the mouse, but they don’t have the right orientation.
Its hard to explain, so here is a picture:
As you can see, the projectile (the yellow part) is moving towards the mouse but is not facing forward, its facing sideward.
I tried this:
Bullet.CFrame = CFrame.new(Bullet.Position, mouse)
But it doesnt work, also, I’m handling the bullet on the server.
Here’s a link to the game, Because its hard to explain:
How can I do this?
Any help is much appreciated!
tannnxr
(tanner)
June 14, 2021, 6:33pm
#2
Simple fix I think
local bullet = --put the bullet here or replace with your own variable however you store the bullet instance
bullet.CFrame = CFrame.new(bullet.Position, mouse.Hit.P)
I get this error:
Hit is not a valid member of Vector3 - Server - Shoot:43
I think that’s because I’m using a server script.
I’m handling the bullet on the server.
I think your getting that error because your assigning a Cframe to a position?
JayO_X
(fakefriends)
June 14, 2021, 6:41pm
#5
Why are you trying to do here? The first argument of CFrame
is where you want the part to be positioned. The 2nd argument is where do you want it to look at.
tannnxr
(tanner)
June 14, 2021, 6:41pm
#6
Because mouse
might be already defined and probably has a Vector3
value inside it.
I’m trying to make my projectile face the mouse.
Hey, do you have any footage of what’s happening here?
I don’t have any recording software, do you understand from the picture?
exp_lol123
(Unavailable)
June 14, 2021, 6:44pm
#10
Not really. Use roblox’s default recording systen.
The projectile doesnt face forward when its being fired out of the gun, it faces sideways, that’s the problem, do you understand?
So, I’m asking how to make it face the mouse when its fired out if the gun.
exp_lol123
(Unavailable)
June 14, 2021, 6:46pm
#12
Now I understand the problem, I’ll look into it.
JayO_X
(fakefriends)
June 14, 2021, 6:46pm
#13
Do you mean this. This is on the client but it works.
local Tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
Tool.Activated:Connect(function()
local Bullet = Instance.new("Part")
Bullet.CFrame = CFrame.new(Tool.Handle.Position, mouse.Origin.Position)
Bullet.Name = "Bullet"
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.P = math.huge
BV.Velocity = mouse.UnitRay.Direction * 50
Bullet.Parent = workspace
BV.Parent = Bullet
end)
The bullet is positioned in the handle and travels to the position the mouse clicked.
I made that already, I’m just asking how to make the bullet orientation face the direction its moving to.
I already said earlier:
exp_lol123
(Unavailable)
June 14, 2021, 6:50pm
#15
Maybe try this:
Bullet.CFrame = CFrame.new(Bullet.Orientation, mouse.Hit.Position)
That doesnt work, Because I don’t think Orientation
is a member of CFrame
.
exp_lol123
(Unavailable)
June 14, 2021, 6:52pm
#17
I’ve tried it and it didn’t give me any errors, might be a coincidence at my end but maybe give it a shot.
I already tried it, and it didn’t work.
exp_lol123
(Unavailable)
June 14, 2021, 6:55pm
#19
Wait, isn’t it that the mouse can only be accessed by the client?
I dont think you understand my problem, I made a working gun system, everything works fine, I just need the bullets orientation to face the mouse.