|
| 28 Jul 2016 12:10 PM |
Full title: mouse.Hit.p returns wrong Vector when aiming at NPCs in first person
Gun script part that matters: local projectile = game.ServerStorage.Projectiles:FindFirstChild("M4Bullet") local acproj = projectile:clone() local bullet = acproj:FindFirstChild("M4Bullet") game.Debris:AddItem(bullet, 5) bullet.Parent = game.Workspace bullet.CFrame = barrel.CFrame bullet.Position = Vector3.new(barrel.Position.X,barrel.Position.Y+0.35, barrel.Position.Z) bullet.CFrame = CFrame.new(bullet.Position,mouse.Hit.p) print(mouse.Hit.p) local v = Instance.new("BodyVelocity", bullet) v.Velocity = bullet.CFrame.lookVector * velocity v.MaxForce= Vector3.new(math.huge, math.huge, math.huge)
velocity = 450 btw.
Main idea is that the bullet is copied from serverstorage.Projectiles, put ontop of the fake barrel and using body force is launched at the mouse.Hit.p. It works alright if aimed at the ground/walls. But if its aimed at players or NPCs Mouse.Hit.p returns a completely wrong value. Any idea why? + Any suggestions on improving the weapon script are really apprectiated.
|
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:27 PM |
| Why it is returning a wrong V3 value, I personally don't really know, probably has something to do with moving parts. And if you want to make it less laggy, make it use rays that appear one after another and make them point downwards to simulate drop. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:28 PM |
| Try pointing at a moving wall or something like that. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:29 PM |
Yeah, tried to avoid rays since i don't have any experience with them. Guess I'll have to use them now.. Anyway, thanks for the answer. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:33 PM |
| Don't give up yet though, rays will act the sane way, but with less lag, so their implementation would be a simple replacement of some functions. Are the bullets flying into tge right direction though? |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:39 PM |
They would fly in the right direction if i wasn't aiming at an NPC or a player. Did some tests with print(mouse.Hit.p). For example, aiming right next to the NPC, at the ground would give me X of lets say 30, aiming at the NPC torso would give me like -90 or smth, aiming from different angles would change it to something different. Let's say moved right alittle, X would be -41 moved left 80. and so on. But if as you say, rays reduce lag then i guess i'll use them. |
|
|
| Report Abuse |
|
|