|
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
| 13 Jun 2017 01:05 AM |
velocity=velocity+time_difference*acceleration
acceleration in studs/second^2 |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 13 Jun 2017 04:37 PM |
@AggressiveCatch Thanks man!
|
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 05:48 PM |
wait.... so how would I time the very first frame?
|
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 05:59 PM |
before the render stepped function
local t= tick() |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|