I feel like my scripting has gotten way better in a short time span, then these issues arise to humble me.
Context: I’m remaking the old classic swords in roblox for a game, a feature I want to include is the lunge making you rise upwards at a steady pace, I don’t want you to shoot up out of no where.
Issue: I can’t seem to figure out LinearVelocities or VectorForces. I also tried the HumanoidRootPart’s AssemblyLinearVelocity. None of them gave me the result I wanted. I assume it’s because the mass of my character was too high but it seemed that too low of a force and my character was glued to the ground, whereas too high of a force and my character would shoot up too fast and too high.
I tried setting all the BaseParts in my character to massless, but I got the same issue just at a lower force.
My goal is something like the levitation effect from Minecraft, a slow glide up. Thank you in advance if anyone knows the solution, I’m pulling out my hair over something that’s probably obvious.
A LinearVelocity should achieve what you are trying to accomplish. I would recommend playing around with the MaxForce and VectorVelocity. There should be a nice sweet spot of these values. You may not want the MaxForce value to be too high, or the velocity might change very quickly and look awkward.
Man I knew it was gonna be obvious, I just didn’t set the MaxForce high enough because I had figured the default 1000 was fine… thanks for the solution, it works great!
You should also take a look into AssemblyMass, since some characters are heavier then others and might go up too far and just not go up at all. What I like to do is simply multiply the velocity with the AssemblyMass, however I am using VectorForces so I’m not sure how it works with other Body Movers.
I tried that and a couple of different solutions like multiplying the total character mass by gravity and then adding as much as you want to go up. And like I said I tried setting every BasePart in the character to massless, it still wouldn’t work.
I tried with LinearVelocity, I just had to turn the MaxForce up to get the player off the ground like @ElusiveEpix said to do. I don’t know much about roblox’s physics system but I was surprised the character being massless still didn’t work.
Also, a quick extra question, does anyone know how to let the character move in whatever direction they’d like to while they’re floating in the air? The best I was able to get was they travel in the direction they were initially going when the LinearVelocity was enabled.
Code on what I did to achieve that:
You shouldn’t use the X and Z components of the VectorVelocity if all you are doing is moving the object up. You could just set the X and Z components of the MaxForce to 0, and it wouldn’t have any effect on horizontal movement.
I’m not using the X or Z of the VectorVelocity, but also I don’t think I have access to the X and Z components of the Max Force, is it a beta feature or am I using the wrong type of force/velocity? I’m using a LinearVelocity?
My bad, I mixed up the old deprecated BodyVelocity with the new LinearVelocity, as the former has MaxForce as a vector and not a scalar.
You will want to change the VelocityConstraintMode to “Line”, then you could set the LineDirection to be up (Vector3.yAxis), then modify the LineVelocity and MaxForce to what you need.
Yesss!! It works perfectly! I didn’t even know that’s what linear VelocityConstraintMode did, thank you so much. I’ll set this as the solution instead since this is the full correct answer.