I know there is vector force, tweens and more. However, what is the best method to move a part to my mouses location once i trigger a function? I want the sphere to act as a golfball and bounce off of any object it is aimed at.
You can see these documentations: BasePart, Understanding Assemblies. Or you can simple set the velocity property of the basepart, but thats not recommended because its deprecated, although its easier to learn.
Definitely not tweens then since they don’t affect physics. Your best bet would be VectorForce or the standard ApplyImpulse
What if I dont want the part to keep going forever, like i want it to have a certain amount of power and after a few seconds it stops rolling?
Prolly ApplyImpulse then, tho I’m not well versed with the physics engine of Roblox. But it should be smth like this:
local sphere = ...
local targetPosition = ...
local timeTaken = 4
local lookDirection = CFrame.lookAt(sphere.Position, targetPosition).LookVector
local speed = (targetPosition - sphere.Position).Magnitude / timeTaken -- Speed = Distance / Time
local force = speed * lookDirection.Unit * sphere.AssemblyMass
Im using linearvelocity now, testing it out. Heres what I got.
https://gyazo.com/b542cb716bcf015e397220eb31f7e4eb
The ball moves properly, however it wants to keep going forward, and doesn’t bounce off of the wall like a golfball with real physics would do after being thrown into a wall. How do I make it bounce off of the wall?
Use ApplyImpulse
, simple as that. It is the more performance friendly method for applying force.
It wont work because its constant you need to make it be applied just once. Or you can use :ApplyImpulse as I said 2 hours ago. (The BasePart documentation)
Applyimpulse wont work for me and im not sure how to make the part go to the mouse position using applyimpulse.
Its irritating, I cant figure out why the golfball isn’t moving. There are no errors either.
Oh for that I suggest doing
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local MousePos = Mouse.Hit.Position
local GolfBall = -- Path to gold ball
local GolfBallPosition = GolfBall.Position
local Direction = (MousePos-GolfBallPosition).Unit -- Return a direction vector. There is a chance it would go the opposite direction but for that do: (GolfBallPosition-MousePos).Unit
local Speed = 10 -- Your Speed in studs per second.
GolfBall:ApplyImpulse(Direction*Speed)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.