@inputs W A S D Space Shift
@persist OffsetFront:vector OffsetBack:vector E:entity
@persist TargetZ V:vector

interval(10)

if(first() | duped()) {
	E = entity():isWeldedTo()
	TargetZ = E:pos():z()
}

OffsetFront = (E:forward()*100) + E:pos()
OffsetBack = (-E:forward()*100) + E:pos()

if(D) {
	E:applyOffsetForce(E:right()*100,OffsetFront)
	E:applyOffsetForce(-E:right()*100,OffsetBack)
}

if(A) {
	E:applyOffsetForce(E:right()*100,OffsetBack)
	E:applyOffsetForce(-E:right()*100,OffsetFront)
}

if(W) {
	E:applyForce(E:forward()*100)
}

if(S) {
	E:applyForce(-E:forward()*100)
}

if(Space) {
	TargetZ++
}

if(Shift) {
	TargetZ--
}

V = (E:pos():setZ(TargetZ) - E:pos()) * 1000

E:applyForce(V + $V*5)

E:applyAngForce((-E:angles():setYaw(0) - E:angVel())*shiftL(ang(E:inertia())))
