|
| 27 May 2017 02:39 AM |
| So, I've made a gun, and I know how to script it, but now I'm wondering which method I should use. I don't want to make it so it just has one ray and instantly hits the target, I want my gun to really have "realistic" bullets that fly. And now my question is: should I use the roblox physics to do this or do I CFrame the bullet or what would be the most efficient way to achieve this? |
|
|
| Report Abuse |
|
|
IODanny
|
  |
| Joined: 19 May 2008 |
| Total Posts: 307 |
|
|
| 27 May 2017 02:58 AM |
| For regular guns, I would go for efficient(Raycasting), because realistically the bullets would be traveling very quickly, so it wouldn't make much of a difference. For slower projectiles like missiles, mortars, and grenades it would probably be best to use CFrame and a lot of math. Parabolas would be your answer!! |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 03:15 AM |
| CFrame + Trajectory Maths (look it up) :) |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 10:10 AM |
| I misused the word "realistic", I'm basing my bullets on a game that is far from realistic, but you can actually see the bullets fly, they go really fast, but still visible though. Thanks for the replies :) |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 10:16 AM |
Quite a nice system I found out about a few days ago is making the effects for your character only show. EG I see my bullets travel really fast but for other people I just see one long beam. You don't really notice it but it's a nice, subtle detail.
You won't be able to support a lot of "flying" bullets. Instead, selectively choose which ones you make fly because that'll save you a lot of trouble when you've got more than 1 person on your game! |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 10:17 AM |
The problem with trajectory though is knowing when it touches something, the touched event is way more efficient than GetTouchingParts and raycasting for exemple.
Also, the bullet just goes in a straight line, there's no bulletdrop. Yeah, I really misused the word "realistic" haha... |
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 27 May 2017 10:35 AM |
Cframe the bullets raycast for collision |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 11:04 AM |
| Each frame, move forward, slow down a bit, and apply gravity. Then do a ray from new pos to the previous pos, and check if you hit anything, if you did, delete the bullet and apply damage if nescecary |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 11:05 AM |
^ Did that, seems like it's a lot less efficient than the regular physics... |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 11:07 AM |
| Its not much less efficient, simply you are doing the physics calculations instead of the default physics system. Will always be slightly less efficient as default physics are c sided so inherently more efficient, however the complete control you get over it more than makes up for this |
|
|
| Report Abuse |
|
|
|
| 27 May 2017 11:13 AM |
| Well I made two version, one with physics and one with raycasting, and when I fire a lot of bullets at once, the raycasting version has a harder time to render it. It's not that big of a deal if you just CFrame it without raycasting(but obviously the bullet really does nothing in that case), but as soon as I add raycasting it becomes quite noticeable. The collision on the physics also work good enough, so I really think I'll stick to physics for now unless some magic new method appears :p |
|
|
| Report Abuse |
|
|
Mescalyne
|
  |
| Joined: 20 Apr 2017 |
| Total Posts: 418 |
|
|
| 27 May 2017 11:42 AM |
| raycast in increments so there's a slight delay between when it shoots and when it hits. then draw the line representing the bullet across each ray. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 27 May 2017 12:00 PM |
Proto, "Then do a ray from new pos to the previous pos, and check if you hit anything" u mixed something up here, DO NOT go from new to previous, go from previous to new, there's a big difference, and if using the (arguably) most commonly used 25 studs per segment then there could have been a few people in the middle of the segment and if u go from new to previous it could either register the wall as the object being hit or the person further away (Which isn't fair since they were most likely playing strategically trying to properly take cover while the nearest player tried fighting back).
|
|
|
| Report Abuse |
|
|
ghulty
|
  |
| Joined: 21 Mar 2011 |
| Total Posts: 42 |
|
|
| 27 May 2017 12:13 PM |
| If the average bullet travels at 2500 equiv. feet per second and Roblox updates at 30 fps, wouldn't you need to shoot something over 80 equiv. feet away to even guarantee the bullet would update on screen once before it hits? (It might have updated to 60 fps in which case half that, but I mean still...) I really think it's overkill unless you're making them super slow. CS:GO, for instance, raycasts but still shows a tiny trail where the bullet went. |
|
|
| Report Abuse |
|
|
|
| 28 May 2017 05:08 AM |
| The bullet is traveling slower than a realistic bullet, but still pretty fast, It is like, just visible. The point really just is that it doesn't hit instantly, there's a delay based on how far the bullet travels. |
|
|
| Report Abuse |
|
|
|
| 28 May 2017 10:55 AM |
| Kap, a ray from A to B, has the exact same effect as a ray from B to A, what the heck are you going on about... |
|
|
| Report Abuse |
|
|
|
| 28 May 2017 10:56 AM |
| Also performance increase noticed with physics may be because the server is doing calculations for every client, which may or may not be a good thing based on what else the server is doing. |
|
|
| Report Abuse |
|
|
|
| 28 May 2017 11:13 AM |
Realistic bullet physics is needlessly complicated, and kind of frustrating for the player. In a lot of cases it's preferable to just use a linear hitscan.
That is, unless you're going for a quake style slow moving projectile nail gun, in which case I would use ROBLOX's physics, b/c CFraming is kind of slow and janky, while if correctly configured with NetworkOwnership physics is extremely smooth, if a little bit laggy (but what isn't on ROBLOX).
If you REALLY want to get into this, you can use some basic physics (kinematics) to calculate the trajectory of the bullet based as a function of initial velocity (constant) and time elapsed (parameter), set a step value, and raycast along the parabola by stepping over time. That's kind of over-engineered, and it's kind of an anti-fun mechanic in a lot of cases. There's a lot of resources outside of ROBLOX for this, but it will require some mathematical understanding on your part.
It's delightful! It's delicious! It's delovely! |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 29 May 2017 08:07 PM |
| Proto, not it is not... Think about it, say I'm at ### ## ### ###### ### ## ### each ray segment is 25 studs, I shoot where I'm facing, there's enemy1 at {0, 0, 10} and enemy2 at {0, 0, 15}, the first ray segment is created and checks the line from {0, 0, 0} to {0, 0, 25}, if checking from A to B then the first one caught is enemy1, however if u did B to A (From {0, 0, 25} to {0, 0, 0}) then the first one caught would be enemy2, get what I mean now? :P |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
| |
|
| |
|