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
 

Re: ROBLOX Physics (range equation)

Previous Thread :: Next Thread 
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
15 Sep 2013 10:35 AM
I'm just wondering, obviously there are things that might need to be adjusted from modern equations when using them in ROBLOX, but exactly what?

I'm assuming the gravity constant (not the big G) needs to be changed from a general 9.8 to.....?
However, even then I still don't seem to get the right answer to this derivative of the range equation.

For instance, I am launching an object of variable mass (which doesn't play a part here) at 20 somethings/seconds. Given that it is 5 studs apart, this equations tells me to launch at around a 3.5 degree angle. Sounded reasonable given the speed and distance, but when I launched it at that angle with that velocity, the ball barely went 1/4 of the way.

What variables need to be adjusted here, or simply in modern physical equations?

local o = create_ball()
local p1, p2 = Workspace.Part1, Workspace.Part2
local direction = (p2.Position-p1.Position)['unit']
local given_velocity = direction * 20
local displacement = (p2.Position-p1.Position)['magnitude']

local range = (math.sqrt((p2.Position.x-p1.Position.x)^2))
local v_magnitude = given_velocity['magnitude']
local angle_needed = math.asin( ((range * 9.8)/(v_magnitude^2)) )

-- R = ((v^s)(sin(2*t))/g
Report Abuse
Maradar is not online. Maradar
Joined: 06 Mar 2012
Total Posts: 4478
15 Sep 2013 10:39 AM
local range and angle_needed should be ^4 in order to get farther.

~Tanner L. Ghosen~
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
15 Sep 2013 10:46 AM
vy*t - 1/2*g*t^2 = 0

vy * t = 1/2*g*t^2
vy = 1/2*g*t
2*vy/g = t

range = vx * t
range = vx * 2 * vy / g

Right?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
15 Sep 2013 10:56 AM
I'm not sure what you're saying with those equations, BlueTaslem, other than that they are also derivatives from the following with without a launch angle.

Distance_x = velocity * time * cosine(theta)
Distance_y = velocity * time * sine(theta) - .5*g*(time^2)
Range = ((velocity^2) * sine(2*theta))/g
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
15 Sep 2013 10:57 AM
Isn't Roblox gravity (20*9.81)?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
15 Sep 2013 10:59 AM
"Isn't Roblox gravity (20*9.81)?"

I used 196.4 as the g constant, but arcsine gave a indefinite answer; which lead me to wonder if there is another factor which needs to be adjusted.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
16 Sep 2013 09:30 PM
Bump
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
16 Sep 2013 10:38 PM
local range = (math.sqrt((p2.Position.x-p1.Position.x)^2))

Are you just trying to evade math.abs() or is there an ulterior motive? Because math.sqrt(x^2) doesn't always work too well depending on the value.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Sep 2013 10:40 PM
> ['magnitude']

Whyyyyy? I see no sane reason to do this.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Sep 2013 10:59 PM
cuz NicNac
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
18 Sep 2013 09:43 PM
So...no known answer so we pick apart the coding habits?

Disappointing, slightly...
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
18 Sep 2013 10:35 PM
Ok, well that math.abs() replacement is pretty atrocious.

How about you interpret the fact that the arcsine doesn't evaluate correctly. There's a good chance it simply means that no matter what angle you choose, you don't have enough v_magnitude to get there.

local g = 9.81 * 20;
if (range * g)/(v_magnitude^2) > 1 then
print("no way!");
else
local angle_needed = math.asin( ((range * 9.8)/(v_magnitude^2)) )
print(string.format("Okey, here's your angle: %.1f", math.deg(angle_needed)));
end


After I post, I'll hit up wikipedia and see if your equations are correct.
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
18 Sep 2013 10:43 PM
Ok, yeah, in doing my research,
a) I noticed this doesn't work for different y levels, and
b) you have to halve the angle that you get from the angle_needed variable.

So yeah, here's how I would do it.

local angle_needed = (range * g / v_magnitude ^ 2) > 1 and math.asin(range * g / v_magnitude ^ 2) / 2 or math.pi / 4;

Or if you don't like spaghetti code,
local sinAngleEquiv = range * g / v_magnitude ^ 2;
local angle_needed;
if sinAngleEquiv > 1 then
angle_needed = math.pi / 4; --Just go as far as you can. The target won't be hit, but you'll get close.
else
angle_needed = math.asin(sinAngleEquiv) / 2;
end
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
19 Sep 2013 07:25 AM
I knew the magnitude wasn't enough from the start. That was obvious.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
19 Sep 2013 09:43 AM
sqrt(acceleration*distance) <= required speed
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