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 » Game Design
Home Search
 

Re: [Scripting] Add inaccuracy to gun

Previous Thread :: Next Thread 
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
20 Jan 2015 08:28 PM
I'm trying to create a way for projectiles to be fired with a varying level of inaccuracy. Some weapons, such as pistols, need to be less accurate than, say, a sniper rifle. But how can I go about adding inaccuracy to ranged weapons?
Report Abuse
bubbaman73 is not online. bubbaman73
Joined: 02 Feb 2013
Total Posts: 795
20 Jan 2015 08:46 PM
maybe you could try to slowly move the projectile in a random direction slowly (or fast, depends) and for 100% accurate dont move it at all?
Report Abuse
Demjot is not online. Demjot
Joined: 15 Jun 2013
Total Posts: 1004
20 Jan 2015 08:47 PM
Are you using raycasting?
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
20 Jan 2015 08:49 PM
Yes, I am using raycasting for the actual hit detection. I am creating a dummy bullet on the clients, though - but that ultimately has nothing really to do with it.
Report Abuse
Demjot is not online. Demjot
Joined: 15 Jun 2013
Total Posts: 1004
20 Jan 2015 09:04 PM
When you cast the ray from the gun to mouse.hit.p, add *CFrame.new(math.random(-MaxSpread, MaxSpread),math.random(-MaxSpread, MaxSpread),math.random(-MaxSpread, MaxSpread))

The MaxSpread should be how many studs off you want it
Report Abuse
Demjot is not online. Demjot
Joined: 15 Jun 2013
Total Posts: 1004
20 Jan 2015 09:06 PM
So over distance, create bullet drop and cast a new ray every few 5-10 studs the bullet goes, make the new ray have the same offset calculations from wherever the first offset landed and so on and so forth
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
20 Jan 2015 09:10 PM
Is there no good way to simply distort the direction by a tiny margin?
Report Abuse
Demjot is not online. Demjot
Joined: 15 Jun 2013
Total Posts: 1004
20 Jan 2015 09:47 PM
If you were using just a projectile, you could slightly tilt the body* but raycasting must go from Point A to Point B directly so offsetting the aim is the best way to go
Report Abuse
CaptainRuno is not online. CaptainRuno
Joined: 03 Sep 2011
Total Posts: 476
20 Jan 2015 10:34 PM
What I do is get the distance from the start to the end then divide that by a number like ten and set that as part of the random so you have this:

local distance = (pointA.Position - pointB.Position).magnitude
local gunInaccuracy = distance/10 -- If point b is ten studs away the can be off by a max of one stud

Report Abuse
powertool is not online. powertool
Joined: 01 Feb 2008
Total Posts: 3771
20 Jan 2015 11:08 PM
I did this a while back, but I created a whole function for raycasting and a whole function to provide spread.

I actually cast two rays: One for the range (and if that misses everything and goes off into space) I then apply a random spread scaled by range to the cframe of the cast.

Then I shoot the cast.

Remember that it's key to SCALE the spread value you get to give the same CONE of spread.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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