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

How do I set the velocity to a part's look vector?

Asked by
Prioxis 673 Moderation Voter
9 years ago

I'm creating a custom gun system but the issue I've ran into is whenever I go to shoot at a certain angle the bullet always travels in the same direction..

issue is on lines 65-69

01wait()
02--services
03local lighting = game:GetService("Lighting")
04local serverstorage = game:GetService("ServerStorage")
05local workspace = game:GetService("Workspace")
06-- variables
07local player = game.Players.LocalPlayer
08local mouse = player:GetMouse()
09local character = player.Character
10local torso = script.Parent.Torso
11local gun = lighting.Models:FindFirstChild("AR15")
12local gun2
13local main
14local cam = game.Workspace.CurrentCamera
15local sprint = false
View all 84 lines...

1 answer

Log in to vote
1
Answered by 9 years ago

LookVector is not a valid part of "main". LoocVector is a children of a part's CFrame. So basically, lookVector is the direction of that part is facing but not the velocity, just the direction.

On line 68, fix it into:

1d.Velocity = character.Head.CFrame.lookVector * (50)

so i used Head because that is the direction your head/face is looking at. (Head.CFrame) means the CFrame of the head. (Head.CFrame.lookVector) means the direction of the head is looking at. (50) is just simply the speed it is launched.

Note: There is also a RayCast method for firing the bullet, but i dont know it yet. So if anyone knows how to fire bullets with RayCast, please answer it for him, then you can choose if you want to use my method or RayCast method. Hope this help!

0
the raycasting part is apart of the older system I'm trying it with a different method kept the raycast thingy in there just in case I decided to not use a part Prioxis 673 — 9y
0
also how do I make the bullets come out of the end of the part called main in the AR15 model? Prioxis 673 — 9y
0
bullet.CFrame = AR15.CFrame.p FlaminSparrow 65 — 9y
Ad

Answer this question