BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 12:02 PM |
I have a game where if you run into the ball, it will fly through the air in the direction that you hit it.
It is very smooth in studio however the ball is VERY glitchy when flying through the air and bouncing while in an actual game, not sure if it is because of the physics or not.
Anyways, here is my code. My question is how can I accomplish the same thing but using BodyForce/BodyVelocity/etc?
local ball = script.Parent local range = 10 local speed = 200
local function getNearestTorso() local closest,dist = nil, range for _,player in pairs(game.Players:GetPlayers()) do local char = player.Character if char then local torso = char:FindFirstChild("Torso") if torso then local distFrom = (torso.Position - ball.Position).magnitude if distFrom < dist then closest = torso dist = distFrom end end end end return closest end
while wait() do local torso = getNearestTorso() if torso then local offset = (torso.Position - ball.Position).unit ball.Velocity = (-offset * speed * 1) end end
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 12:04 PM |
My thinking is that if I use forces it will be smoother.
Also I feel like it doesn't help that this code does so many calculations so often
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 12:44 PM |
Bump
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 01:00 PM |
I realize this is tricky and the code would be a little long
I just need an idea not a whole script
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 01:38 PM |
^
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2016 01:45 PM |
| Stop constantly setting its velocity. |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 01:53 PM |
It's not constantly setting the velocity. It only sets its velocity if a player is within the given range
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 02:18 PM |
:(
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 04:39 PM |
bump
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 23 Jan 2016 05:48 PM |
bump
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
Darkenus
|
  |
| Joined: 17 Jul 2014 |
| Total Posts: 1997 |
|
|
| 23 Jan 2016 05:50 PM |
have you tried playing with the physics options in game.Workspace
thats my only tip as i dont do well with cframe, velocity, magnitude (and all artificial movement to say) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 10:37 AM |
Yes i have, almost no difference
Still glitchy
Bump |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Jan 2016 10:59 AM |
Your checking very quickly - in the event there is a torso nearby, you're looking at it and executing a positional change on the ball every 1/30th of a second.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 03:14 PM |
But it only executes the positional change in the split second that a torso is within a very small range
Basically yes it checks for a torso every 1/30th second, but it only changes its velocity once in the event there is a torso in the set range
So not really executing a positional change every 1/30th of a second. Because very, very soon after the ball is "hit", the ball flies away from the given range, thus the code no longer executes on it
BUT that's not even my question. My question is how do I do the same thing this code does, but by applying BodyForce/BodyThrust/BodyVelocity rather than just the velocity of the ball.
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 24 Jan 2016 03:29 PM |
It would be an incredible feat to reach any measure of accuracy with a bodyvelocity/thrust/force... but I'm not well versed with those things. #pitybump
|
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 04:31 PM |
qq
I just want to make its motion smoother
Anything ideas will help
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 04:34 PM |
| Your game is laggy, fix it. |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 04:35 PM |
Lol
You see that is what I'm trying to do here, yes?
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 06:02 PM |
okay final bump
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 06:04 PM |
| Use a touched event instead |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 08:22 PM |
I've already tried that, it's like 3x worse
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 08:26 PM |
Why not try game:GetService("RunService").RenderStepped:wait(0.001) or something like that?
Ignorance at its finest. |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 24 Jan 2016 08:43 PM |
I'd prefer less calculations rather than more
Or is there some benefit of using that I don't know about ?
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 09:24 PM |
| Use a touched event with a debounce |
|
|
| Report Abuse |
|
|