BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 08 Nov 2015 02:04 AM |
So, let's say my character is running at a ball. How do I apply a force at the point at which I hit the ball to make it fly in that direction?
I'm trying to work with BodyThrust, but I have little experience with it... I'm assigning the BodyThrust's position to the position of the character at the point of impact, but how do I then figure out what Vector3 force needs to be applied to the ball?
It seems like a physics application and I may need to solve for it but if there is a simpler solution, please enlighten me....
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2015 02:12 AM |
So you're trying to make the ball move away from the nearest player? It's actually pretty simple. You just have to find the nearest torso, take the unit offset between the torso and the ball, and multiply it by the speed of the ball.
local self = script.Parent local range = 20 local speed = 10
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 - self.Position).magnitude if distFrom < dist then closest = torso dist = distFrom end end end end return closest end
while wait(0.3) do local torso = getNearestTorso() if torso then local offset = (torso.Position - self.Position).unit self.Velocity = (offset*speed) end end |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 08 Nov 2015 02:33 AM |
@clone
Thanks so much- I'll see what I can do with it and will let you know how it goes
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|
BobCowMan
|
  |
| Joined: 14 May 2010 |
| Total Posts: 22634 |
|
|
| 08 Nov 2015 08:46 AM |
Wow, it works- I would have never thought to do it like that. Thank you!
Though I would like to still know if I could have done it with body thrust
3:8 BCM / Speedyseat(co-owner) |
|
|
| Report Abuse |
|
|