Linear Velocity, PlaneVelocity glitching and deleting parts

  1. What do you want to achieve? Keep it simple and clear!
    I want units to stop spinning out of control then deleting.
  2. What is the issue? Include screenshots / videos if possible!
    Units that are larger in size glitch out.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried editing custom physical properties, changing the magnitude threshold and have looked on the developer hub.

It followed the MRTS movement tutorial and adjusted where I needed to. Units have linear velocity named “vel” and are attached to the models primary part named “Hitbox”. The attachment that vel is connected to is also set to Hitbox’s assembly mass position.

if unit:FindFirstChild("MOVING") then
				task.spawn(function()
					local loop = true
					unit.MOVING.Value = true
					while loop and unit.Parent and positions[unit] == endGoal and unit.ATK.Value == false  do
					
						unit.PrimaryPart.CFrame =	CFrame.lookAt(unit.PrimaryPart.Position, endGoal*Vector3.new(1,0,1)+Vector3.new(0,unit.PrimaryPart.Position.Y,0)
						)

						task.wait()

						local hitpos = endGoal
						CFrame.lookAt(unit.PrimaryPart.Position, hitpos)
						unit.PrimaryPart.Vel.PlaneVelocity = Vector2.new(hitpos.X - unit.PrimaryPart.Position.X, hitpos.Z - unit.PrimaryPart.Position.Z).Unit * unit.UnitStats.SPEED.Value

						if ((unit.PrimaryPart.Position - positions[unit]).Magnitude > 2 and unit.Parent and positions[unit] == hitpos) then
						
						elseif unit.ATK.Value == true then
							print("time to stop moving")
							loop = false
							unit.MOVING.Value = false
						else
							loop = false
							unit.MOVING.Value = false

						end

						
						
					end

					if unit.Parent then
						unit.PrimaryPart.Vel.PlaneVelocity = Vector2.new(0, 0)
					end

If anyone can help me out figure out how to stop this I would appreciate it greatly. Using bodyvelocity and gyro also has the same issue. Thanks!

The unit is probably too tall making its magnitude to that point higher than 2 even when its directly above it.

perhaps make positions[unit] higher on the Z axis by half of the unit’s height?

Evening!

I changed:

if ((unit.PrimaryPart.Position - positions[unit]).Magnitude > 2 and unit.Parent and positions[unit] == hitpos) then

to:

if ((unit.PrimaryPart.Position - positions[unit]).Magnitude > unit:GetExtentsSize().Z and unit.Parent and positions[unit] == hitpos) then
```

and it feels some what better but the model still vanishes from what I assume is because of the velocity if I spam click.

My bad they get destroyed when i set their move position close to where they stand. Just found that out right now.

1 Like

Just curious, but do you know what is destroying them? (Like did you do that yourself, or is there some other issue?)

I don’t know how to explain it but its like the part goes past height limit and gets destroyed. I did not do it myself and it stems from PlaneVelocity which is linear velocity

I see.

I am not very familiar with all the goofy velocity things roblox has, but perhaps try printing the values that you’re using (CFrames, vectors) to see if any of them are going crazy.

1 Like

Wait actually

do you think the issue might be due to you clicking on the unit itself?

yea it happens when i right click aka move the unit EXACTLY where its position is.

i tried this. It gets deleted before it can even be printed lol. weridly enough its still stored in the selected units table

Where are you printing it? you should print the values before they’re actually used to move the unit.

i just figured something out atm though. When i right click the unit it signals to attack itself. Attacking uses cframe.lookat so maybe if its looking at itself and multiplying against itself it is flinging it out of bounds.

yep this was the issue. Thank you SO SO SO MUCH! for the inital part. The getting the Z of the model worked and mixed with not attacking itself no more errors. Thank you.

1 Like

(idk if you’d want to know this but additional info anyways, I would assume that the lookat is breaking because its trying to do tan(0/0) to find the angle)

Its looking at the models primary part for the inital vector3 value then looking at the target’s primary position then + some vector3 values to keep them on a 2d plane. Having a unit look at itself is just bad from the start. I literally had to edit one line which was

old:
if unit.UnitStats.TEAM ~= TEAM then
m.Event("Attack")

new:
if unit.UnitStats.TEAM.Value ~= TEAM then
m.Event("Attack")

some quality of life improvements would be making movement less stutterish. as in the video it stutters. I could be wrong but could stem from the movement being server instead of client. But we will see. Saved my RTS game. Thank you.

1 Like

Try looking on the server tab after telling the unit to move. If its also stuttery there, it might be another problem, otherwise, you could just send the unit’s final location to all the clients, and have them also move the unit to achieve a smoother movement. (Idk how you’d deal with replication though, its definitely possible since people seem to do that alot of the times)

my scripts are in a spider web but i have a system that does client and server replication at the same time. like oddly server sided projectiles look like client sided cause of this system**. What did you mean by server tab btw?**

(whats a spider web lol)

I don’t think you should be replicating everything on the client to the server nor vice versa (Atleast not manually, since roblox should already do that). What I meant was that you want the client to be moving the objects itself instead of waiting for the server to update its position.

By the server tab, I mean that button on the top right corner of the “Test” section which either says “Client” or “Server” which allows you to switch between server-view and client-view.

gottcha. DW the system has no FPS drops when 187 units are on screen. MAYBE a ping spike from a memory leak i need to fix teehee