Hello, I would like to know how to use velocity in two axes at the same time (X and Y axis), the idea of this is that when a ball collides with the box the ball is thrown with the velocity in the X and Y axis.
How could I do that?
You can use body movers.
01 | local debris = game:GetService( "Debris" ) |
02 |
03 | box.Touched:Connect( function (partTouched) |
04 | if partTouched = = ball then |
05 | local bodyVelocity = Instance.new( "BodyVelocity" ,ball) --create a body velocity and parent it to the ball |
06 | bodyVelocity.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) -- Determines the limit on how much force that may be applied to each axis |
07 | bodyVelocity.P = 1000 -- Determines how aggressive of a force is applied in reaching the goal velocity |
08 | bodyVelocity.Velocity = ball.CFrame.lookVector * 100 + Vector 3. new( 0 , 50 , 0 ) -- make the goal of the velocity 100 studs out from where the ball is looking and up 50 studs. |
09 | debris:AddItem(bodyVelocity, 0.5 ) -- deletes the bodyVelocity after 0.5 seconds. You can adjust this value and the other values above to your liking |
10 | end |
11 | end |
If you have any issues let me know.