I want to create a grappling system using BodyVelocity. The problem is that I want the character to be able to tilt left or right depending on their key. Currently, it seems to have no effect.
API.shootBullet = function(Box)
local newBullet = Box.PrimaryPart.Bullet:Clone()
Box.PrimaryPart.Shooter.Beam.Attachment1 = newBullet
newBullet.Parent = Box.PrimaryPart
local startPos = Box.PrimaryPart.Shooter.WorldPosition
local endPos = startPos + Mouse.Hit.LookVector * DMGSettings.BulletSpeed
local ray = Ray.new(startPos, (endPos - startPos).Unit * DMGSettings.BulletSpeed)
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Character})
if hit then
newBullet.Parent = hit
newBullet.WorldPosition = pos
newBullet.Orientation = Character.PrimaryPart.Orientation
State = "Following"
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(1,1,1) * 1000
BodyVelocity.Velocity = CFrame.new(pos).RightVector * 100
BodyVelocity.Parent = Character.PrimaryPart
coroutine.wrap(function()
local Velocity = (pos - Box.PrimaryPart.Shooter.WorldPosition).Unit * DMGSettings.BulletSpeed / 4
while State == "Following" do
wait()
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
--Velocity = Velocity * DMGSettings.BulletSpeed + CFrame.new(pos).RightVector * -20
elseif UserInputService:IsKeyDown(Enum.KeyCode.A) then
--Velocity = Velocity * DMGSettings.BulletSpeed + CFrame.new(pos).RightVector * 20
else
Velocity = (pos - Box.PrimaryPart.Shooter.WorldPosition).Unit * DMGSettings.BulletSpeed / 4
end
Character.PrimaryPart.Velocity = Velocity
--BodyVelocity.Velocity = Velocity
end
end)()
else
local newPart = Instance.new("Part")
newPart.Anchored = true
newPart.CanCollide = false
newPart.Transparency = 1
newPart.Position = endPos
newPart.Parent = game.Workspace
newBullet.Parent = newPart
newBullet.WorldPosition = newPart.Position
--> If you didn't hit anything reset state
delay(.25, function()
State = "N/A"
newPart:Destroy()
newBullet:Destroy()
end)
end
end
As you can see, I’ve tried editing the character’s primary part velocity, I’ve tried adding RightVector relative to the hit position and etc.
EDIT: I’ve noticed that 2 BodyVelocity will work against each other, the new one overlaps the old one.
Then try adjusting the velocity of the first bodyvelocity, and force move the character directly. Ex: if a or left pressed then character.cframe = character.cframe*(5,0,0)
(Obviously this is pseudo code).
Also, look into bodyposition, that moves an object from one position to another whereas bodyvelocity moves it in a direction. Pretty sure that’s what you’ll have to use to do what you want ex: a body positon parented to primarypart, bodyposition.position = hit.position (of course you’ll have to tweak the other values of bodyposition so it moves at the speed you want)
These body movers rotate the character itself, what I’m trying to do is apply force on one side of the character. The goal is for the character to be able to circle around the tower.
Moving the character directly will make a glittering effect and is not appealing to the eye. I’ve looked into bodyposition and it will not help me achieve what I want to do. BodyPosition will directly move the character to the position and it’s at an inconsistent rate which are things I want to avoid.
EDIT: Adding any offset to the BodyPosition’s Position will also not work because the position is the end goal
If you move it at small intervals over time, it’ll look the same. That’s how all moving works. so do something like while a or left pressed move 0.01 wait().
No, it moves it at a fixed rate, and how fast it moves can be tweaked.
It doesn’t just do endgoal, it does current position to end goal. I missed to say that when you update character’s position, update bodyposition’s position as well.
while true do
wait() game.Workspace.Mystifine:SetPrimaryPartCFrame(game.Workspace.Mystifine.PrimaryPart.CFrame * CFrame.new(0,1,0))
print("and")
end
Moving at 0.01 stud every wait() does nothing
The overall speed is the same but the movement is sine or something like that, it’s clear that the part slows down upon reaching the target. I’ve also noticed an odd moving pattern, I expected it to move diagonally to the target (shortest distance)
Then try a higher value, I used that as an example. Try 0.1 or 0.2 etc.
It appears you’re right here. So back to what I initially said then, move the character then re-calculate the direction they have to move in and update the bodyvelocity’s velocity to that direction.
I don’t know for sure if the speed decrease with bodyposition can be dealt with, I’ll have to play around with its other properties and see what they do.