Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make an object bounce? [closed]

Asked by 10 years ago

The game i am working on needs bouncing stuff.

Closed as Too Broad by Articulating

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Certain size parts should bounce on their own. But, if you want a trampoline-like part, just set the Velocity property of an anchored part to something like 0, [VERTICAL VELOCITY], 0. To do it from a script (more durable; won't randomly remove the velocity when repetitively testing: part.Velocity = Vector3.new(0, vertical, 0)) The same thing can be achieved with a bouncing part after a touched event.

local part = script.Parent

part.Touched:connect(function(hit)
    local bounce = part.Velocity.magnitude -- Gets the current magnitude of the velocity.
    part.Velocity = Vector3.new(part.Velocity.x, math.abs(bounce / 2), part.Velocity.z) -- 'bounce / 2' halves the current velocity. The math.abs makes it the positive of the number (absolute), to make sure it bounces UP.
end)

This can get pretty in-depth. Very complex versions can bounce by what face hit the part. (Reflection-like bouncing)

Ad