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: adding acceleration to velocity in renderstepped??

Previous Thread :: Next Thread 
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 12:46 PM
My script adds acceleration to velocity, updating every 60th of a second with renderstepped. Or so I thought... In the script you can see that I actually have to divide the acceleration by 3600 total in order to get the correct 3 stud per second squared acceleration I want. Why is this and on another note, how can I adjust this script to accommodate FE in the future?


local cam = workspace.CurrentCamera
local position = workspace:WaitForChild("pos")
local focus = workspace:WaitForChild("focus")
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
--[[
player.CharacterAdded:connect(function()
cam.CameraSubject = focus
end)
]]
--cam.CameraType = "Custom"

local part = {}

function part.new(acceleration, velocity, position)
local self = setmetatable({}, {__index = part})
self.acceleration = acceleration
self.velocity = velocity
self.position = position

return self
end

function part:Update()
self.velocity = self.velocity + self.acceleration/60
self.position = self.position + self.velocity
end

local rocket = part###############################t##############us.CFrame)

wait(1)
cam.CameraSubject = focus
local ti = tick()
print("Start Position" ..tostring(focus.Position))
RunService.RenderStepped:connect(function()
if tick()-ti <= 1 then
rocket:Update()
focus.CFrame = rocket.position
print(rocket.position.p)
end
--cam.CFrame = focus.CFrame * CFrame.new(Vector3.new(25,0,0))*CFrame.Angles(0,math.pi/2,0)
end)
if tick()-ti >= 1 then
print("End Position" ..tostring(focus.Position))
end


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 12:49 PM
In the part that is "###" out, I set the acceleration equal to a vector with 3/60 in the y axis.


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 01:30 PM
b1


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 02:36 PM
b2


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 05:12 PM
b3


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 05:45 PM
b4


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
12 Jun 2017 10:17 PM
b5


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
13 Jun 2017 12:04 AM
b6


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
13 Jun 2017 12:16 AM
just use a body velocity
Report Abuse
EvilDonutNoob is not online. EvilDonutNoob
Joined: 26 Jan 2014
Total Posts: 440
13 Jun 2017 01:05 AM
velocity=velocity+time_difference*acceleration


acceleration in studs/second^2
Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
13 Jun 2017 01:46 PM
@Wunder_Wulfe I need finer control than what I would get with roblox objects

@EvilDonutNoob Right... that is why I originally multiplied the acceleration by 1/60 of a second since that is my average framerate. It still doesn't explain how 1/3600 of the acceleration is the mathematically correct constant to multiply the acceleration by.


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
13 Jun 2017 03:08 PM
Okay.... I derped pretty bad.

self.position = self.position + self.velocity

yeah that's wrong. I just corrected the line to read

self.position = self.position + self.velocity * (1/60) + .5 * self.acceleration ^ 2

according to the kinematic equation

x = x(initial) + v(initial)*t + 1/2 at^2

Anyway.... While I get nearly 60 frames per second at all times, I still don't know how I would make the time vary for those who get lower framerates. For example, if someone gets 20fps in my game, the calculations in these scripts would be invalidated, since I am using the constant 1/60 for the amount of time passed between each calculation. Please help!


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
13 Jun 2017 03:12 PM
Save a variable, say "t", to hold the tick() of the previous render stepped fire

self.position = self.position + self.velocity * (tick()-t) + .5 * self.acceleration ^ 2
Report Abuse
OldGuest1331 is not online. OldGuest1331
Joined: 15 Jan 2017
Total Posts: 59
13 Jun 2017 03:21 PM
░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄
░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█
░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█
▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█
▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█
▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌
▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐
▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌yess
▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█
▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀
▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀
▒▒▒▒▀▄▐▒▒▒▒▒▒▒▒▒▒▒▒▒▐
▒█▀▀▄ █▀▀█ █▀▀█ █▀▀█   ▀▀█▀▀ █░░█ █▀▀   ▒█▀▀█ █▀▀█ █▀▀ █▀▀
▒█░▒█ █▄▄▀ █░░█ █░░█   ░▒█░░ █▀▀█ █▀▀   ▒█▀▀▄ █▄▄█ ▀▀█ ▀▀█
▒█▄▄▀ ▀░▀▀ ▀▀▀▀ █▀▀▀   ░▒█░░ ▀░░▀ ▀▀▀   ▒█▄▄█ ▀░░▀ ▀▀▀ ▀▀▀
║████║░░║████║████╠═══╦═════╗
╚╗██╔╝░░╚╗██╔╩╗██╠╝███║█████║
░║██║░░░░║██║╔╝██║███╔╣██══╦╝
░║██║╔══╗║██║║██████═╣║████║
╔╝██╚╝██╠╝██╚╬═██║███╚╣██══╩╗
║███████║████║████║███║█████║

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄
________________________________
| Windows Dialog                   [-] [口] [×] |
|  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄  ̄ |
| Windows has detected that this song is awesome! |
| Do you agree?        |
|    ______    ______    _____   |
|    | Yes   |   | Maybe |     |   No  | |
|     ̄ ̄ ̄ ̄ ̄ ̄     ̄ ̄ ̄ ̄ ̄ ̄     ̄ ̄ ̄ ̄ ̄  |
|______________________________ __ _|

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█░░░░░░░░▀█▄▀▄▀██████░▀█▄▀▄▀██████
░░░░ ░░░░░░░▀█▄█▄███▀░░░ ▀█▄█▄███

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▀▀█▀▀ ▒█▀▀▀█ ▒█░▒█ ▒█▄░▒█ ░█▀▀█ ▒█▀▄▀█ ▀█▀ █ █ █
░▒█░░ ░▀▀▀▄▄ ▒█░▒█ ▒█▒█▒█ ▒█▄▄█ ▒█▒█▒█ ▒█░ ▀ ▀ ▀
░▒█░░ ▒█▄▄▄█ ░▀▄▄▀ ▒█░░▀█ ▒█░▒█ ▒█░░▒█ ▄█▄ ▄ ▄ ▄

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█░░░░░░░░▀█▄▀▄▀██████░▀█▄▀▄▀██████
░░░░ ░░░░░░░▀█▄█▄███▀░░░ ▀█▄█▄███
Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
13 Jun 2017 04:37 PM
@AggressiveCatch Thanks man!


Report Abuse
bigboy77584 is online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
13 Jun 2017 05:48 PM
wait.... so how would I time the very first frame?


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
13 Jun 2017 05:59 PM
before the render stepped function

local t= tick()
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
13 Jun 2017 06:00 PM
or you can just assume the first frame is 1/60 because one frame shouldn't affect too much, whatever you want really
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