Hi, my problem is to do with scripting a moving part for a magic spell.
So basically, when a player casts a spell I can a script which fades in a part for the spell, more specifically a dragon head, then add a force to fire it towards the mouse.Hit
. The part’s size varies, it is calculated using this code:
local size = Vector3.new(0.96, 0.84, 1.68) + Vector3.new(5.76, 5.04, 10.08) * multiplier
part.Size = size
multiplier
is the level of the player’s spell, as a fraction of the maximum level for the spell, therefore it always falls between zero and one. Where multiplier
= 0, the part is about the size of the character’s head. Where multiplier
= 1, the part is roughly 90% the height of the character, and the width/length grow proportionally.
Problem is, I have no clue how to vary the force applied so that the part travels at the same speed regardless of size/mass, which is what I’m trying to achieve. I have had no problem with direction, just not enough force being applied or way, way too much.
So far, I’ve extensively tried BodyVelocity, BodyPosition and BodyForce. BodyVelocity wouldn’t work when the part was large, even if I multiplied the velocity by math.Huge. BodyPosition would move in a weird manner, I guess I just don’t know how to use it. And with BodyForce, I just can’t get my numbers right. I’ve had the part set to massless, doesn’t seem to change anything.
Using BodyForce, I’ve tried using exponentials, for example:
BodyForce.Force = part..CFrame.LookVector*500 + part.CFrame.LookVector*part.Mass^3
,
which works well for the heavier parts, but absolutely flops for the smaller parts.
I’ve tried using a base plus an exponential, for example:
BodyForce.Force = part.CFrame.LookVector*500 + part.CFrame.LookVector*part.Mass^3
,
but again, it just doesn’t keep the speed constant for all size values.
For extra information: the part’s mass ranges from 0.91 to 205. To describe the speed I want the part to travel at, I’m going for a speed where you can see it coming, but its pretty hard to dodge and impossible to keep up with. Sorry if that’s too vague, I can work out the speed I’m going for if needed.
Should I resign from using BodyMovers and just tween the part? Thus far I’ve avoided doing that, because I want the part to have a very natural and constant motion. I’m at a loss right now, any input is appreciated, thanks for reading all that.