So, I have a coordinate, that is the parts location (some red cylinder) and it needs to go to a specific direction (a white dot, that is where the player clicks on) with velocity, it doesn’t have to be full reach, it just has to be near where the white dot goes. How could I do such thing?
I want to use basepart:ApplyForce() but I don’t know what vector3 to put in it.
There is many ways to create projectiles, but here is one simple way you should be able to do it (I did not test this, but I believe it should work):
local projectile: BasePart = ... --projectile part
local startPosition: Vector3 = ... --could be the projectile position or a character limb
local targetPosition: Vector3 = ... --mouse hit position in the world, usually
local velocity = 10 --desired velocity in studs/sec
local lookDirection: Vector3 = CFrame.lookAt(startPosition, targetPosition).LookVector --unit vector of the direction towards the target
local velocityVector: Vector3 = lookDirection * velocity --create a velocity vector that has a direction
projectile:ApplyImpulse(velocityVector) --apply the velocity force instantly on the projectile
Edit: (correction)ApplyImpulse takes in a force, not a velocity, so this just means that you will need to increase the velocity variable value in my code to be higher if the projectile has more mass (heavier) and fails to shoot anywhere.
Now what I need is to know where the part it collided with will go at. If it hits someone, another player, the script would detect if it touched it, find the position of the cylinder, then the position of the player, then it needs to produce a new position of where the player would go at based on the position of the cylinder and the player.
So if the cylinder is below the player when touched, then the next position the player will go at is upward, if it is behind the player it will make the player go forwards. How would I find this third vector3 with these other 2?
Edit: I already solved this. Substraction is the difference of two pieces for a reason, so finding the difference between the two gets me the difference, then I have to separate the original piece with that difference I just got.