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

How do i make so the gun's bullet go where i want it to go?

Asked by 3 years ago
Edited 3 years ago

Script

Bullet.CFrame = CFrame.new(gunPos, MousePos)
Bullet.Orientation = Vector3.new(Ori)
Bullet.Velocity = char.HumanoidRootPart.CFrame.lookVector * Speed

Variables

gunPos = Gun.Handle.Position

MousePos = Mouse.Hit.p

Ori = Gun.Parent.HumanoidRootPart.CFrame.lookVector

Problem

I don't understand, the bullet of my gun doesn't go where my mouse is but it goes straight. And it doesn't rotate, it stays at it's default orientation.

What am i doing wrong here? Should i use something else for the mouse? ( Like Mouse.UnitRay.Direction or Mouse.Hit.lookVector )

0
There is actually something called bezier curves, I reccomend this https://devforum.roblox.com/t/modeling-a-projectiles-motion/176677 but if you dont understand, you could read this wiki roblox made https://developer.roblox.com/en-us/articles/Bezier-curves kepiblop 124 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

You're using the look vector as the direction that the bullet travels in, and not the mouse position. The bullet is travelling in a straight line from the look vector of the humanoid root part, and the orientation doesn't matter for velocity. You can instead do something like this (I'm not that good at scripting this might not work)

Bullet.Position = gunPos
Bullet.AssemblyLinearVelocity = (mouse.hit - gunPos).Unit * Speed

Here we get the vector from the gun to the mouse position, and convert it to a unit vector so that the distance of the mouse from the gun doesn't influence the speed, and multiply it by the speed.

Also, if you're using velocity to calculate the bullet's path, it'll be affected by gravity. If you don't want this to happen, you can use raycast for the bullets instead. You can just look at dev forum posts and other scripting helpers questions to help you with that.

Ad
Log in to vote
0
Answered by
3F1VE 257 Moderation Voter
3 years ago

use tutorials on youtube.com

0
???????????????????????? kepiblop 124 — 3y

Answer this question