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
 

Damage Direction

Previous Thread :: Next Thread 
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
20 Sep 2016 01:28 PM
I'm trying to create that red rounded bar that you see in FPS games when you get damaged, it shows which direction the bullet that hit you was coming from. I got the angle correct, I managed to make it face the right direction, but I'm struggeling to get it in the right position, here is what I got so far:

plr is the player that shot the bullet(not relevant yet) and dir is the lookVector if you were to make a CFrame that origins in the HumanoidRootPart and faces the origin of the bullet, so CFrame.new(HumanoidRootPart.Position, bullet.Position).lookVector

FunctionTable.DamageRecieved = function(plr, dir)
if player.PlayerGui.ScreenGui:findFirstChild(player.Name) == nil then
local im = Instance.new("ImageLabel", player.PlayerGui.ScreenGui)
im.BackgroundTransparency = 1
im.Image = "http://www.roblox.com/asset/?id=506680074"
im.Size = UDim2.new(0.15, 0, 0.3, 0)
local front = player.Character.HumanoidRootPart.CFrame.lookVector-Vector3.new(0, player.Character.HumanoidRootPart.CFrame.lookVector.y, 0) --ignore y coordinate
local angled = dir-Vector3.new(0, dir.y, 0) --ignore y coordinate
local angle = math.acos((front:Dot(angled))/(front.magnitude*angled.magnitude))
local relpos = (angled-front).Unit/5
if relpos.x < 0 then
angle = -angle
end
im.Rotation = math.deg(angle) --rotation is correct
im.Position = UDim2.new(0.5+relpos.x, 0, 0.5+relpos.z, 0) --this line is not correct, help here please :)
end
end

Any help is much appreciated!
Report Abuse
Mitko0o1 is not online. Mitko0o1
Joined: 30 Nov 2010
Total Posts: 5725
20 Sep 2016 01:34 PM
Direction = (tool.Handle.Position - bullet.Position).unit
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
20 Sep 2016 01:36 PM
^ That hasn't really got anything to do with my post... I'm not shooting a bullet, I'm getting shot by a bullet. I also know the 3D position already, I now need to translate this ########## to a 2D position in the #### ## you know what I mean with that red bar thingy from an fps that indicates where the bullet was coming from? Maybe I could illustrate with a picture if you want.
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
20 Sep 2016 03:11 PM
hes not wrong
if you didnt know, it is simply the equation of finding the offset of one point from another

you can just move it around by converting the vector into euler angles
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
21 Sep 2016 12:38 AM
I know he's not wrong, but it's not what I need...
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
21 Sep 2016 04:59 AM
worldspacetouispace or wahtever sorry no time gl lol
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
21 Sep 2016 07:00 AM
^
what? lol
Report Abuse
dadibox1234 is not online. dadibox1234
Joined: 05 Dec 2013
Total Posts: 320
21 Sep 2016 07:15 AM
Je pouras pas t'aider pour sa, Trop dure pour moi ^^
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
22 Sep 2016 03:30 AM
Okay, I have more time now.

So;
You know where you got hit, so cast it from HumanoidRootPart towards the point to you got hit to get an unit factor.

Then,
decompose the angles and you can place it on your UI.
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
22 Sep 2016 03:41 AM
FunctionTable.DamageRecieved = function(plr, dir)
if player.PlayerGui.ScreenGui:findFirstChild(player.Name) == nil then
local length = 0.3
local width = 0.15
local im = Instance.new("ImageLabel", player.PlayerGui.ScreenGui)
im.Name = player.Name
im.BackgroundTransparency = 1
im.Image = "http://www.roblox.com/asset/?id=506680074"
im.Size = UDim2.new(width, 0, length, 0)
local v = Instance.new("Vector3Value", im)
v.Name = "Dir"
v.Value = dir
local front = player.Character.HumanoidRootPart.CFrame.lookVector-Vector3.new(0, player.Character.HumanoidRootPart.CFrame.lookVector.y, 0)
local angled = dir-Vector3.new(0, dir.y, 0)
local angle = math.acos((front:Dot(angled))/(front.magnitude*angled.magnitude))
local relpos = (angled-front).Unit/5
if relpos.x < 0 then
angle = -angle
end
im.Position = UDim2.new(0.5+math.sin(angle)/3-length/2, 0, 0.5-math.cos(angle)/3-width/2, 0) --this is the important line
im.Rotation = math.deg(angle)
end

Yesterday I thought about decomposing it as well and it got closer to the result I wanted to achieve, but not close enough... I added -length/2 and -width/2 because the moving position of an ImageLabel is the top left corner and rotation is around the middle of the ImageLabel, which is really just ######## ### So I added that to compensate for that, but it still doesn't give the desired effect.
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
22 Sep 2016 03:45 AM
"but it still doesn't give the desired effect."

What do you want then?

Also, I'm not great with vectors so I can't help a lot :/
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
22 Sep 2016 03:51 AM
It's only correct for angles 0 to 180, 180 to 360(or how it's scripted in here: -180 to 0) are really glitchy, at some parts it's inverted and at some parts it just does some weird stuff...
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
22 Sep 2016 03:57 AM
I don't know more, sorry.

My only guess left is math.abs()
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
22 Sep 2016 04:09 AM
I changed

if relpos.x < 0 then
angle = -angle
end

to

if relpos.x < 0 then
angle = math.pi*2-angle
end

which gives a better result... at least when the angle is smaller than 90 or bigger than 270, god this script frustrates me.
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
22 Sep 2016 04:13 AM
Try googling it.
Report Abuse
HarrySnotte is not online. HarrySnotte
Joined: 27 Jun 2011
Total Posts: 2854
22 Sep 2016 04:13 AM
Nvm, it works... Thanks though :p
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
22 Sep 2016 04:14 AM
Good luck! :)
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