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

Rocket Propulsion to Position?

Asked by 4 years ago

Hi, I was just wondering if it is possible to make the target of rocket propulsion a position?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Yes it is possible. You add a BodyPosition to the part (you'll use this to move the part) and a BodyGyro so that the part can maintain it's orientation.

Next, you give a new vector3 position to the body position (which is the target you define) and it will take care of moving the rocket to the set position.

While trying to make you a good example for you to learn on, I got a little bit into it and ended up making this: https://gyazo.com/6101070a14ad802ce698164e7bd9a5cc

I basically get the 3d position in the world from the mouse hit then I create a part and give it a BodyPosition and a BodyGyro and I define the position of BodyPosition to the position of the mouse.Hit. Finally, I add a touch interest to the part so that it gets destroyed when it hits something other than the character and create an effect explosion.

Next, to make sure that the part is CanCollide false with the player that shoots the projectile, I created 2 collision groups (One for the objects and the other for the player) and set collisions between both groups to false. I then added every basepart of the character in the player collision group and made it so each spawned projectile's collision group is the Objects group.

Here's my local script (This goes in StarterPack) so it resets everytime the player dies:

01-- Services
02local Players = game:GetService("Players")
03local UserInputService = game:GetService("UserInputService")
04local PhysicsService = game:GetService("PhysicsService")
05-- Variables
06local localPlayer = Players.LocalPlayer
07local mouse = localPlayer:GetMouse()
08local localChar = localPlayer.CharacterAdded:wait()
09local localCharHumRootPart = localChar:WaitForChild("HumanoidRootPart")
10local part = script.Parent
11local targetPart = game.Workspace:FindFirstChild("TargetPart")
12-- Configs
13local speed = 3000
14local dampening = 500
15-- Functions
View all 85 lines...

And here's my server script (Goes in ServerScriptService):

01local PhysicsService = game:GetService("PhysicsService")
02 
03-- Create collision groups so the projectile cannot hit the player
04local function CreateCollisionGroups()
05    local players = "Players"
06    local objects = "Objects"
07 
08    PhysicsService:CreateCollisionGroup(players)
09    PhysicsService:CreateCollisionGroup(objects)
10 
11    -- Make collision between players and objects false
12    PhysicsService:CollisionGroupSetCollidable(players, objects, false)
13end
14 
15for i=1,1 do
View all 41 lines...

I used a body position and a body gyro to move the part and keep it's orientation. But keep in mind you could also simply use the tween service to tween either the position of the part or the CFrame of the part.

0
I will work on it tonight. TheReverseGaming 29 — 4y
0
Let me know how it goes. Don't forget to set the question as answered though if this helped you :) DevMaster333 215 — 4y
0
I'm confused, how would I use this. I am trying to make a pet go beside the player. TheReverseGaming 29 — 4y
0
Nvm I got it to work TheReverseGaming 29 — 4y
Ad

Answer this question