Can someone explain this code to me?

So here the code is putting a body position in front of you(its a dash script) but what i dont understand is why is the programmer multiplying the lookvector * 25 does that but it 25 studs infront of the lookvector or something?

Edit - Dir = Char.HumanoidRootPart

So. the LookVector is the direction in which the front surface is facing, and * 25 is the place to go, that also determines the speed. It it was set to. So for example it is telling the BodyPosition to go in the direction that the “Dir” is looking with a force of 25 exerted onto it.

BP.Position  = HRP.Position + (Dir.lookVector * (100)) 

It will be going much faster.

Considering I can not see what the variables are representing, I can’t pinpoint exactly what he is doing.

1 Like

To add onto this, LookVector is a unit vector, which means that your LookVector will always total to 1 in Magnitude. The programmer in question is getting your current pos, then adding on (directionYouAreFacing * 25), by multiplying by 25 they are making the LookVector out of 25 and therefore 25 studs in length. This makes you move forward 25 studs

1 Like

lookVector is the unit vector (1 stud) in the direction you are going. Multiplying it by 25 means the humanoidRootPart is being forced by the body position forward 25 studs.

This code creates a BodyPosition BodyMover in the HumanoidRootPart. The target position that the BodyPosition should bring its model towards (in this case, the character) sports two parts.

  • HRP.Position: Used to set the position of the BodyPosition to where the player currently is.

  • Dir.lookVector * 25: This part takes the lookVector of Dir (the place where Dir is pointing at) and multiplies it by 25. In a way, you could indeed say that this means 25 studs out. The number is arbitrary and in this case, it refers to studs.

Essentially, this code takes the place Dir is facing and extends that out by 25, then adds that to the position of the HumanoidRootPart and sets the resulting vector as the BodyPosition’s Position (the target it needs to reach).

If you understand vector components, that may be relevant here. lookVector is the forward component of the vector from Dir, meaning it’s a scalar value. Multiplying it by 25 essentially says “go 25 out”.

1 Like