|
| 03 Feb 2017 07:52 AM |
Title.
Basically, you know in those games where when you aim at an moving enemy, theres like a floating box which will predict where the bullet will hit?
You can go to google and type in "gun pipper" to see what I mean.
How much maths will this involve, what kind of code will it be? What does the code look like? |
|
|
| Report Abuse |
|
|
|
| 03 Feb 2017 08:13 AM |
surface guis probably
ooorrrr camera:WorldToScreenPoint
get the enemies position, and then get the screen point of the enemy to make a gui there or somethign
|
|
|
| Report Abuse |
|
|
|
| 03 Feb 2017 08:17 AM |
nvm don't listen to what i said above
do you mean like something that accounts for lead?
probably need to get the velocity of the enemy ship/plane/whatever, and do something with bullet speed and distance
i can't do the exact math rn
if someone hasn't answered this, ill make a formula later
|
|
|
| Report Abuse |
|
|
|
| 03 Feb 2017 08:51 AM |
Yeah, I want the gun reticle to lead its targets. So if the target is moving fast, the reticle will show where to aim so the bullet will hit the moving target.
Hope it doesn't involve too much maths xD |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 03 Feb 2017 09:22 AM |
in that case then yes, that will require some linear algebra to calculate the physics of the moving projectile, and speed of the enemy.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 03 Feb 2017 10:08 AM |
Do you want me to elaborate on this? Qyazo .gif link: /bd88c61267ceb72e3f340ff4bde2c440
|
|
|
| Report Abuse |
|
|
RogueMage
|
  |
| Joined: 28 Jan 2012 |
| Total Posts: 1235 |
|
|
| 03 Feb 2017 11:16 AM |
that looks like a lot of math ^
too lazy |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 03 Feb 2017 11:21 AM |
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=208871231
|
|
|
| Report Abuse |
|
|
|
| 03 Feb 2017 06:43 PM |
soybeens example, but instead of using cframe it uses bodyposition (*might* be better to use body position in a plane?)
replace the local script in the screengui>frame with this
repeat wait() until game.Players.LocalPlayer.Character
local bulletSpeed = 500
local shrink = true --whether the targeting thing shrinks with distance or not
local throughParts = false --whether the targeting thing can be seen if there is a part between the player and the enemy local ignoreList = {workspace:WaitForChild('Trackpart'),game.Players.LocalPlayer.Character} --ignore list of the throughParts checking
local playerPart = game.Players.LocalPlayer.Character:WaitForChild('Head') --the player local enemyPart = workspace.Trackpart --the enemy
-----------------------------------------------
game:GetService('RunService').RenderStepped:Connect(function() local plr = playerPart.Position local enemy = enemyPart.Position local enemyVelocity = enemyPart.Velocity local distance = (plr - enemy).magnitude local t = distance/bulletSpeed local lead = enemy + (enemyVelocity * t) local worldToScreenPoint = workspace.CurrentCamera:WorldToScreenPoint(lead) local Pos = UDim2.new(0,worldToScreenPoint.X,0,worldToScreenPoint.Y) local depth = worldToScreenPoint.Z if depth > 0 then script.Parent.Position = Pos if not throughParts then local r = Ray.new(plr,(enemy-plr).unit*distance) local hit = workspace:FindPartOnRayWithIgnoreList(r,ignoreList,false,true) if hit then script.Parent.Visible = false else script.Parent.Visible = true end end if shrink then script.Parent.Size = UDim2.new(0,math.min(10/(depth/100),10),0,math.min(10/(depth/100),10)) end end end)
and replace the script in the part to this, as well as add a bodyposition to the part:
while wait(3) do script.Parent.BodyPosition.Position = Vector3.new(math.random(100,250),math.random(100,250),math.random(100,250)) * script.Parent:GetMass() end
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:12 AM |
| Thank you! This forms the fundamentals for ## gun targeting system. After looking through the code there's a lot less maths than I originally anticipated which is always a good thing since I'm not particularly great at the subject |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:21 AM |
i read your desc
are you trying to make an ace combat type game
i remember when i used to play ace combat 4....
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:28 AM |
Yup, set in the same fictional world as the rest of the AC series!
I can do all the 3D modelling, environment work as well as sound and whatnot. But I am having a lot of trouble with scripting considering I'm new (hence I post scripting questions frequently in these forums)
My next and potentially last hurdle before having all the groundwork of the game laid out is the flight mechanics, but I'll start on that later. |
|
|
| Report Abuse |
|
|