I am using this code to draw a line for showing user the direction and power of the force.
var start = new pc.Vec3(this.startPos.x, this.startPos.y, 0);
var end = new pc.Vec3(event.x, event.y, 0);
var color = new pc.Color(1, 1, 1);
var worldLayer = this.app.scene.layers.getLayerById(pc.LAYERID_IMMEDIATE);
this.app.renderLine(end, start, color, {
layer: worldLayer
});
That does not work. How can I draw a line and apply force towards that direction?
Renderline has to be called every frame to be shown as it’s a debug feature. We don’t have a built in line renderer yet but I would suggest using pc.Mesh https://developer.playcanvas.com/en/api/pc.Mesh.html to render the line which give you much more flexibility in size and shape.
Hi guys @Leonidas and @Francisco_Bozzo thanks for your replies. I am trying to draw a line onMouseMove method. I tried to move that code to the update method but still no line
Here is the project. I am trying to do that in mouse-input.js of orbit camera. I know it’s not the best way to do that but I am just trying to make it work first.
Firstly, this.lastPos sometimes gets incorrect value, where you are setting 3D vector with .set(x, y) without z. This will corrupt the location, so you should use .set(x, y, z) instead.
Also make sure your ranges are correct. They look pretty large. For example, a distance from the center of the field to the gates is about 30, while your line coords starts and ends go in hundreds. The line could be well out of camera view. Try with fixed coordinates first, instead.