generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: mouse.Hit.p returns wrong Vector when aiming...

Previous Thread :: Next Thread 
armandis1122 is not online. armandis1122
Joined: 02 Sep 2010
Total Posts: 54
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
nooneisback is not online. nooneisback
Joined: 28 Feb 2012
Total Posts: 1672
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
nooneisback is not online. nooneisback
Joined: 28 Feb 2012
Total Posts: 1672
28 Jul 2016 12:28 PM
Try pointing at a moving wall or something like that.
Report Abuse
armandis1122 is not online. armandis1122
Joined: 02 Sep 2010
Total Posts: 54
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
nooneisback is not online. nooneisback
Joined: 28 Feb 2012
Total Posts: 1672
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
armandis1122 is not online. armandis1122
Joined: 02 Sep 2010
Total Posts: 54
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image