adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 10:19 AM |
I understand math.random() and a few others but I tried understanding the rest in
http://wiki.roblox.com/index.php?title=Function_Dump/Mathematical_Functions
and I don't understand what they mean... Wiki is confusing they don't explain it. Can anyone help me understand them or refer to better source? |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 10:56 AM |
| I need help because I'm trying to make my first gun and its so confusing :/ |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 11:08 AM |
Well I'm getting really frustrated... I hate making guns :(. What am I missing!?!?!?
P.s No errors and print(1) does appear
code-
--[[ Made by - adeep This script makes the gun shoot --]]
------------------------------------------ -------------References------------------- local tool = script.Parent local handle = tool.Handle local character = nil
local Ref_maxTotalAmmo = tool.MaxTotal local Ref_maxInClip = tool.MaxInClip local Ref_ammoInClip = tool.InClip local Ref_totalAmmo = tool.TotalAmmo
------------------------------------------ -------------Variables-------------------- local var_maxTotalAmmo = 100 local var_maxInClip = 10 local var_ammoInClip = 10
local Mouse = nil
local firstTimeEquipped = false
local target = nil -- called in CheckAmmo local characterPos = nil -- called in CheckAmmo
------------------------------------------ --------Used to check ammo---------------- function CheckAmmo() if firstTimeEquipped == false then Ref_maxTotalAmmo.Value = var_maxTotalAmmo Ref_maxInClip.Value = var_maxInClip Ref_ammoInClip.Value = var_ammoInClip end if Ref_ammoInClip.Value > 0 then characterPos = character.Head.Position target = Mouse.Target characterPos = character["Head"].Position CreateBullet() end return end
------------------------------------------ ------Used to get target direction-------- function ComputeDirrection() local lenSquared = characterPos.magnitude^2 local invSqrt = 1 / math.sqrt(lenSquared) return Vector3.new(characterPos.x * invSqrt, characterPos.y * invSqrt, characterPos.z * invSqrt) end
------------------------------------------ --------Used to create bullet------------- function CreateBullet() ComputeDirrection(characterPos) wait(ComputeDirrection) local Bullet = Instance.new("Part") Bullet.Size = Vector3.new(2, 1, 1) Bullet.Velocity = ComputeDirrection() local pos = character["Head"].Position + (characterPos * 18) Bullet.CFrame = CFrame.new(pos, pos + characterPos) Bullet.BrickColor = BrickColor.new("Bright yellow") Bullet.Reflectance = 0.1 Bullet.Locked = true Bullet.CanCollide = true Bullet.Anchored = false Bullet.Name = "Bullet" Bullet.Parent = game.Workspace print(1) return end
------------------------------------------ ------Runs when tool is equipped---------- function Equipped(mouse) character = tool.Parent Mouse = mouse mouse.Button1Down:connect(CheckAmmo) end
------------------------------------------ ----------Used to call events------------- tool.Equipped:connect(Equipped)
|
|
|
| Report Abuse |
|
|
|
| 03 Dec 2014 11:23 AM |
"local lenSquared = characterPos.magnitude^2 local invSqrt = 1 / math.sqrt(lenSquared)"
Isn't that a less efficient way of doing 1/characterPos.magnitude?
Since you aren't really using the square thingy, don't leave it there. |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 11:27 AM |
| This whole making a gun thing is really advanced... It didn't have no different effect. What I'm not understanding is why isn't it shooting the "Bullet" I make in "CreateBullet()" function? |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2014 11:29 AM |
Probably because you are multiplying the head's position by 18.
If you stand next to 0, 0 then the bullet might actually be visible. |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 11:32 AM |
| Thanks man. But its creates a new "Bullet" in same spot in air and it doesn't "Shoot". Ik I'm missing something i just don't know what it is. |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 11:38 AM |
| I forgot to add Bullet.Position... But it still doesn't "Shoot/Go anywhere" and how to determine witch value Bullet.Position.X or Bullet.Position.Z needs to have like +3 so it doesn't pop up in my head c.c? |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 03 Dec 2014 12:08 PM |
| Use CFrames? *-z is forward for CFrames. |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 12:11 PM |
I did use CFrames? Ugh I have a headache XD. Where do I need to add/change something and why?
--[[ Made by - adeep This script makes the gun shoot --]]
------------------------------------------ -------------References------------------- local tool = script.Parent local handle = tool.Handle local character = nil
local Ref_maxTotalAmmo = tool.MaxTotal local Ref_maxInClip = tool.MaxInClip local Ref_ammoInClip = tool.InClip local Ref_totalAmmo = tool.TotalAmmo
------------------------------------------ -------------Variables-------------------- local var_maxTotalAmmo = 100 local var_maxInClip = 10 local var_ammoInClip = 10
local Mouse = nil
local firstTimeEquipped = false
local target = nil -- called in CheckAmmo local characterPos = nil -- called in CheckAmmo
------------------------------------------ --------Used to check ammo---------------- function CheckAmmo() if firstTimeEquipped == false then Ref_maxTotalAmmo.Value = var_maxTotalAmmo Ref_maxInClip.Value = var_maxInClip Ref_ammoInClip.Value = var_ammoInClip end if Ref_ammoInClip.Value > 0 then characterPos = character.Head.Position target = Mouse.Target characterPos = character["Head"].Position CreateBullet() end return end
------------------------------------------ ------Used to get target direction-------- function ComputeDirrection() local lenSquared = characterPos.magnitude local invSqrt = 1 / math.sqrt(lenSquared) return Vector3.new(characterPos.x * invSqrt, characterPos.y * invSqrt, characterPos.z * invSqrt) end
------------------------------------------ --------Used to create bullet------------- function CreateBullet() ComputeDirrection(characterPos) wait(ComputeDirrection) local Bullet = Instance.new("Part") Bullet.Size = Vector3.new(2, 1, 1) Bullet.Velocity = ComputeDirrection() local pos = character["Head"].Position + characterPos Bullet.CFrame = CFrame.new(pos, pos + characterPos) Bullet.BrickColor = BrickColor.new("Bright yellow") Bullet.Reflectance = 0.1 Bullet.Locked = true Bullet.CanCollide = false Bullet.Anchored = false Bullet.Name = "Bullet" Bullet.Position = Vector3.new(characterPos.x,characterPos.y,characterPos.z) Bullet.Parent = game.Workspace print(1) return end
------------------------------------------ ------Runs when tool is equipped---------- function Equipped(mouse) character = tool.Parent Mouse = mouse mouse.Button1Down:connect(CheckAmmo) end
------------------------------------------ ----------Used to call events------------- tool.Equipped:connect(Equipped)
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 03 Dec 2014 12:14 PM |
Bullet.Position = Vector3.new(characterPos.x,characterPos.y,characterPos.z)
Try something like
Bullet.Position = (CharacterHeadCFrameOrSomething*CFrame.new(0,0,-3)).p |
|
|
| Report Abuse |
|
|
adeep
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 274 |
|
|
| 03 Dec 2014 12:21 PM |
I understand why this is wrong but I'm not getting what your recommended. I'm sorry I'm being dumb I have a big headache now and have never ever made a gun before... Idk if it's just me or not but guns suck to make...
Code-
Bullet.Position = (characterPos*CFrame.new(0,0,-3)).p
Error-
attempt to multiply a Vector3 with an incompatible value type or nil |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2014 12:47 PM |
I remember I was trying to make my own Gun, now it's made... check it, Test Subject Uzi...
plr = game.Players.LocalPlayer mouse = plr:GetMouse()
--all the Code here
Bullet.CFrame = Bullet.Position, mouse.Hit.p Bullet.Velocity = Bullet.CFrame.lookVector * 100 --change 100 to watever speed u want |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 03 Dec 2014 12:53 PM |
You used characterPos, which is a Vector3. You need to use the CFrame, not the V3 |
|
|
| Report Abuse |
|
|