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 » Scripting Helpers
Home Search
 

Re: Physics question

Previous Thread :: Next Thread 
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 06:59 AM
How would i get how hard a block hit another block, including the angle at which a block, hits the other block(I dont care what angle the first block is at)

this the formula i can use if the object is a sphere....
total = (touchedpart.Velocity-block.Velocity).magnitude --difference in speed
range = (block.Position-touchedpart.Position).magnitude--how far away the 2 blocks are
lv = CFrame.new(Vector3.new(0,0,0),block.Velocity).lookVector --the velocity with a magnitude of 1
force = (lv*range-touchedpart.Position+block.Position).magnitude--how close the lv is to the position of the sphere
force = force/range --changes it to a percent
force = -force+1 --changes it to be postive, in reverse
print(force)

hope 8:00 isnt to early for you guys
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 07:11 AM
Why do you care of such? What are you attempting? Speak now or suffer eternal death.

'game.Players.jetta765214:Destroy()'
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 07:15 AM
collision engine. I had a basic version of this, and it is a lot of fun to play around with on building games. Such as you can have a destruction derby, a war where the bases are destroyable. If you crash your car, it breaks and/or explodes. I just cant figure out this part. I need this part sort of badly, so the bug where the car's wheel repeatidly hits the ground when driving on a flat surface doesnt happen...
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 07:24 AM
If there was a way to create boundaries in cube, then i could just use the sphere script...

Such as a 10*10*10 cube, would have 1000 cubes inside it when a collision happens, i just see which cube is closest to the collision and use that for the physics engine... I Would rather use Vector3 instead of spawning up the 100s of cubes needed.... The easiest way would be to use welds, but i dont want to have to spawn cubes up in the firstplace....

You have any tips for this, or another way to do it?
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 07:56 AM
I forgot how you would calculate force, depending mass and velocity.

if force > insertyourforcethatbreaksmyitemhere then
print('Breaks my item')
end

Calculate force yourself.
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 07:58 AM
im already using speed,mass, and the mass of objects connected to the object that is touched. I just need at what angle the object hits the other object. I would like to know if its just a glancing blow, and does nothing, or direct, like a car running into a brick wall.
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:02 AM
if blockthathit.Rotation = Vector3.new(0,0,0) then
print('Destroy, smooth collision')
else
print('Do less damage, lazy to calculate, Not smooth collision')
end

Party me
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 08:10 AM
lol, found a way to use my bounce box strategy...
Also .Rotation is a nil value, isnt it?
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:14 AM
Rotation is a property of Part, so it shouldn't be nil.
Report Abuse
ashispro is not online. ashispro
Joined: 14 Sep 2008
Total Posts: 452
07 Sep 2013 08:14 AM
Use part.CFrame.lookVector to get the Vector3 direction that the part is facing - try experimenting with that
Report Abuse
ashispro is not online. ashispro
Joined: 14 Sep 2008
Total Posts: 452
07 Sep 2013 08:17 AM
Positive X = Coming from Right
Positive Y = Upwards angle
Positive Z = ?
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:18 AM
@ashispro

Wrong. Learn the term of relativity. X = Coming from Right RELATIVE TO THE AXES.
But not to the right of the part themselves.
Report Abuse
ashispro is not online. ashispro
Joined: 14 Sep 2008
Total Posts: 452
07 Sep 2013 08:20 AM
@Dragon,

that's not my problem, I'm just hinting towards something that he could use

no need to be on your meriod about it
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:23 AM
lal k bruh u happ3h n0w bruh? yu g0t yo lewt nao git 0uut
Report Abuse
ashispro is not online. ashispro
Joined: 14 Sep 2008
Total Posts: 452
07 Sep 2013 08:24 AM
"getting out" is still a thing is it? I said that when I was what? 12 years old? lol it's nice to see the autism is still in this game
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:27 AM
I wasn't even paying attention to what I said, lulz. Stay here, and die with us. JK
Report Abuse
ashispro is not online. ashispro
Joined: 14 Sep 2008
Total Posts: 452
07 Sep 2013 08:29 AM
I think I have already died reading RBX.Lua again. It's so easy! :<

Back to C++ it is
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
07 Sep 2013 08:30 AM
Kewl, I ish 12, screeptin is fun
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
07 Sep 2013 08:45 AM
I've pretty much finished the script now... here is a copy that just does the calculations, no damage implemented yet:

sensitivity = 100
explosions = true
removed = false
parts = {}
groups = {}
group_sensitivity = .1
strength = 1--need to imploment

game.Players.PlayerAdded:connect(function(player)--Chat settings
player.Chatted:connect(function(chat)
if string.sub(chat,1,10) == "explosions" then
explosions = not explosions
elseif string.sub(chat,1,6) == "remove" then
removed = not removed
end
end)
end)

function get_orentation(part,vector)
local look = part.CFrame.lookVector
local y = (CFrame.new(Vector3.new(0,0,0),look)*CFrame.Angles(math.pi/2,0,0)).lookVector
local x = part.CFrame.lookVector
local z = (CFrame.new(Vector3.new(0,0,0),look)*CFrame.Angles(0,0,math.pi/2)).lookVector
local new_vector = Vector3.new(vector.x*x,vector.y*y,vector.z*z)
return new_vector
end

function sen(num)
return math.floor(num/group_sensitivity*group_sensitivity)
end

function get_groups()
for i,v in pairs(groups) do
groups[i] = nil
end
local temp_group = {}
local temp_values = {}
for i,v in pairs(parts) do --sorts parts into a table
local vel = v.Velocity
vel = Vector3.new(sen(vel.x),sen(vel.y),sen(vel.z))
if temp_group[vel] == nil then
temp_group[vel] = {}
temp_group[vel][#temp_group[vel]+1] = part
temp_values[#temp_values+1] = vel
else
temp_group[vel][#temp_group[vel]+1] = part
end
end
for i,v in pairs(temp_values) do
if v ~= Vector3.new(0,0,0) then
groups[#groups+1] = temp_group[v]
end
end
end

function find_and_return(part)
for i,v in pairs(groups) do
for _,parts in pairs(v) do
if parts == part then
return v
end
end
end
end

function check_point_in_bounds(part,bounds)
local bound = part:Clone()
bound.CFrame = part.CFrame+Vector3.new(0,1000,0)
bound.Transparency = 1
bound.Anchored = true
local test = Instance.new("Part")
test.FormFactor = "Custom"
test.Size = Vector3.new(0,0,0)
test.Position = bounds+Vector3.new(0,1000,0)
if test.Position == bounds+Vector3.new(0,1000,0) then
test:Destroy()
bound:Destroy()
return true
else
test:Destroy()
bound:Destroy()
return false
end
end

function collision(part1,part2)
--create bound boxes
bound_boxes = {}
if part2.Shape == "Block" then
for x = 1,part2.Size.x do
for y = 1,part2.Size.y do
for z = 1,part2.Size.z do
bounce_boxes[#bounce_boxes+1] = get_orentation(part2,Vector3.new(x,y,z))
end
end
end
elseif part2.Shape == "Wedge" then
for x = 1,part2.Size.x do
for y = 1,part2.Size.y do
for z = 1,part2.Size.z do
local orentation = get_orentation(part2,Vector3.new(x,y,z))
if check_point_in_bounds(part2,orentation) then
bounce_boxes[#bounce_boxes+1] = orentation
end
end
end
end
end
closest = {distance = math.huge,point = Vector3.new()}
for i,v in pairs(bound_boxes) do
if (part1.Position-v).magntiude < closest.distance then
closest.distance = (part1.Position-v).magntiude
closest.point = v
end
end
local total_velocity = (part1.Velocity-part2.Velocity).magnitude
local total_mass = 0
for i,v in pairs(find_and_return(part1)) do
total_mass = total_mass+v:GetMass()
end
local range = (block.Position-closest.point).magnitude
local lv = CFrame.new(Vector3.new(0,0,0),part1.Velocity).lookVector
local force = (lv*range-closest.point+part1.Position).magnitude
force = force/range
force = -force+1
force = force*total_velocity*total_mass
print(force)
end

function add_part(part)
parts[#parts+1] = part
part.Touched:connect(function(part2) collision(part,part2) end)
get_groups()
end

function remove_part(part)
for i,v in pairs(parts) do
if v == part then
parts:remove(i)
end
end
get_groups()
end

function scan(model)
for i,v in pairs(model) do
if v:IsA("BasePart") then
add_part(v)
end
if #v:GetChildren() > 1 then
scan(v)
end
end
end

game.Workspace.ChildRemoved:connect(function(block)
remove_part(block)
end)

game.Workspace.ChildAdded:connect(function(block)
if block:IsA("BasePart") then
add_part(block)
elseif block.ClassName == "Model" then
scan(block)
end
end)

delay(0,function()
while true do
wait(15)
get_groups()
end
end)

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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