|
| 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 |
|
|
|
| 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
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 1004 |
|
| |
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 20 Jan 2015 09:10 PM |
| Is there no good way to simply distort the direction by a tiny margin? |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|