How would I do this?

So I basically want to make a part.

That appears at a certain position. That position we will call the origin.

Anyhow I want the part to appear at the origin, fly upwards and outwards in a random direction away from the origin.

Anyway to achieve this?

And I also dont want to use some kind of physics thing. Cause I would like to be able to tell every time it moves.

Cool thx!

2 Likes

Hello, you can try to use tweenservice to make part fly upwards and outwards.
here’s a script that might help

local part = script.Parent
local TweenService = game:GetService("TweenService")
local origin = part.Position

local finalPosition = origin + Vector3.new(0, 10, 0)

local randomX = math.random(-10, 10)
local randomY = math.random(-10, 10)
local randomZ = math.random(-10, 10)
local randomDirection = Vector3.new(randomX, randomY, randomZ).Unit

finalPosition = finalPosition + randomDirection * 10
local tweenInfo = TweenInfo.new(
    1, 
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out, 
    0, 
    false,
    0 
)

local tween = TweenService:Create(part, tweenInfo, {Position = finalPosition})
tween:Play()

1 Like

Problem. How would I tell every time it moves? I have to detect for it to hit something.
Oh I forgot to mention. I need it to go up, and out and then go down to the ground

Or down until it detects something.

Also you dont have to write an entire script. I just need to know how!

The Origin is the Center of the World, or 0, 0, 0, you then to get a Random Direction for it to Follow.

local origin = Vector3.zero -- 0, 0, 0

local rmd = Random.new() -- psuedorandom
local Direction = rmd:NextUnitVector() -- Returns a Random Direction

For you to Detect whether it hit something, you would most likely need to Raycast to do it, which you would need to Cast based on its position, and then by the Direction its going, if your Raycast was Successful, you can stop the Part, as to check if its Moving, you can have a Variable called IsMoving and when a Ray Intersects something, say its false, if you want it to go backwards you can then Reverse the Direction (-Direction) and have it go back.

1 Like

to detect if it moves you can use RunService and check if part.Position ~= previousPosition (use variable to store previous position). And then connect RunService with Heartbeat so it’ll loop constantly, then if you want make it print("Part moved to: " … tostring(part.Position)) to check where part moved.
If you need it to go to the ground then use another tween and make it’s position to the ground

yes that’s probably the better way, or use collisiongroups to detect whether it collided with something or not

Cool Ill try this out!

As of the raycast part. Thanks for reminding me about them I forgot about them for a second

So as of me being me.
Am I suppose to input values here?

as of now It always appears under the position, I want it to be level with the origin, not below.
So anyway to fix this?