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: Physics/Scripting Application

Previous Thread :: Next Thread 
BobCowMan is not online. 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
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
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 is not online. 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 is not online. 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
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