miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 07:51 PM |
script.Parent.Equipped:connect(function(equip) script.Parent.Activated:connect(function(active) p = Instance.new("Part",Workspace) p.Name = "Bullet" p.Anchored = false p.CanCollide = false p.Position = script.Parent.Handle.Position mes = Instance.new("SpecialMesh",p) mes.MeshType = "FileMesh" mes.Scale = Vector3.new(.9,1,1) mes.MeshId = "http://www.roblox.com/asset/?id=2697549" mes.TextureId = "http://www.roblox.com/asset/?id=2697544" body = Instance.new("BodyVelocity",p) body.P = 1500 body.maxForce = Vector3.new(5000,5000,5000) body.velocity = Vector3.new(0,0,10) end) end)
Everything works. Though, The bullet goes the wrong way. How do I make it go wherever the mouse clicked goes? I tried saying the MouseButton1 Event but it didn't work. Help? |
|
|
| Report Abuse |
|
|
Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 23 Feb 2012 08:08 PM |
| You never told it to go where aiming. You simply made it spawn, with a velocity that always moves it one direction. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 08:11 PM |
Yeah, I know. I want to know how to make it know where to go. What do I say to make it aim.
velocity = Vector3.new(mouse.Hit.P)
That? I tried that and it said it's an invalid member. I'm sorry, I'm new to BodyVelocity, can you explain? |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 08:47 PM |
RBX.Lua = case sensitive...
mouse.hit.p -_-
`*\~-{ Are we there yet T.T? }-~/*` |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 08:48 PM |
Wait... WHERE DID YOU DEFINE MOUSE?
`*\~-{ Are we there yet T.T? }-~/*` |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 09:08 PM |
| Mouse is an object of roblox, right? |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 09:08 PM |
If you define it....
`*\~-{ Are we there yet T.T? }-~/*` |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
|
| 23 Feb 2012 10:02 PM |
Try this. I'm not great with this kind of stuff.
script.Parent.Equipped:connect(function(equip) script.Parent.Activated:connect(function(active) p = Instance.new("Part",Workspace) p.Name = "Bullet" p.Anchored = false p.CanCollide = false p.Position = script.Parent.Handle.Position mes = Instance.new("SpecialMesh",p) mes.MeshType = "FileMesh" mes.Scale = Vector3.new(.9,1,1) mes.MeshId = "http://www.roblox.com/asset/?id=2697549" mes.TextureId = "http://www.roblox.com/asset/?id=2697544" body = Instance.new("BodyVelocity",p) body.P = 1500 body.maxForce = Vector3.new(5000,5000,5000) * game.Players.LocalPlayer.Character.Torso.lookVector body.velocity = Vector3.new(0,0,10) end) end
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:05 PM |
I shot it, it went up not the way I wanted. And the second time I tried output said this
Players.Player.Backpack.Gun.Shoot:15: attempt to index field 'LocalPlayer' (a nil value)
|
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:06 PM |
"I shot it, it went up not the way I wanted." Explain.
And is this actually a localscript like it should be?
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:07 PM |
It didn't go straight, the bullet just kept on going up and up and up
Erm...No -______-____- i'm taking a guess it should be a localScript? |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:08 PM |
Yes, absolutely.
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:09 PM |
| When I put it in a localscript it didn't error but the bullet went up not straight. |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:11 PM |
Do you want it to go perfectly straight?
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:12 PM |
| I want it to go where ever you click it. Where ever the mouse is clicked that's where I want it to go. |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:12 PM |
But do you want it to go perfectly straight to that point?
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:13 PM |
| Yes. Click it, bullet goes where you click it and straight. |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:16 PM |
Well then you're totally not doing this right. You need the function to remember where the mouse clicked, then use a BodyPosition, not BodyVelocity, and set it's position property to the point where the mouse clicked, with a P of a large number and a D of 0.
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:20 PM |
I'm sleepy and I'm going elsewhere. I've been doing homework for 4 and a half hours today plus an hour and a half of pit orchestra. If you need more help, PM me and I'll probably answer tomorrow sometime after school.
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 23 Feb 2012 10:22 PM |
How come this doesn't work?
script.Parent.Equipped:connect(function(equip) equip.Button1Down:connect(function(mouse) p = Instance.new("Part",Workspace) p.Name = "Bullet" p.Anchored = false p.CanCollide = false p.Position = script.Parent.Handle.Position mes = Instance.new("SpecialMesh",p) mes.MeshType = "FileMesh" mes.Scale = Vector3.new(.9,1,1) mes.MeshId = "http://www.roblox.com/asset/?id=2697549" mes.TextureId = "http://www.roblox.com/asset/?id=2697544" body = Instance.new("BodyPosition",p) body.P = 1000 body.D = 0 body.maxForce = Vector3.new(1000,1000,1000) body.position = Vector3.new(mouse.hit.P) end) end)
|
|
|
| Report Abuse |
|
|
|
| 23 Feb 2012 10:48 PM |
script.Parent.Equipped:connect(function(mouse) script.Parent.Activated:connect(function() local bullet = Instance.new("Part",Workspace) bullet.Name = "Bullet" bullet.CanCollide = false bullet.CFrame = CFrame.new(script.Parent.Handle.Position, mouse.Hit.p)
local mesh = Instance.new("SpecialMesh",bullet) mesh.MeshType = "FileMesh" mesh.Scale = Vector3.new(.9,1,1) mesh.MeshId = "http://www.roblox.com/asset/?id=2697549" mesh.TextureId = "http://www.roblox.com/asset/?id=2697544"
local bodyForce = Instance.new("BodyForce",bullet) bodyForce.force = (script.Parent.Handle.Position - mouse.Hit.p).unit * -1e4 end) end)
Here's using a BodyForce like I suggested in the PM you sent me.
Haters gonn' hate. |
|
|
| Report Abuse |
|
|
Riderj
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 1534 |
|
|
| 23 Feb 2012 10:53 PM |
@Off-topic
I am dreading the day when I start development on the guns for my game. It will be such a difficult achievement, mainly because I cannot get the bullets to move. They just pop out of the gun and sit there, haha.
[[ 7/10 - Scripting| 4/10 - Building | 10/10 - Confused ]] |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 23 Feb 2012 10:54 PM |
"script.Parent.Equipped:connect(function(equip) equip.Button1Down:connect(function(mouse)"
The Button1Down event of the mouse does't get the mouse as it's argument, you already have the mouse... it was the argument which was passed to the Equipped event, and you gave it the name 'equip' which confused yourself. Now in the script the 'equip' variable is really the mouse object, so you want:
body.position = Vector3.new(equip.Hit.p)
And you notice that I also changed the capitalization of the 'Hit' and 'p' parts. This is VERY important as other posters in the thread pointed out, you MUST have the correct capitalization for everything or else the script will not run. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|