Renderline won't work

Are you calling that every frame?

It is there. The angle is awkward, so you can only see it when camera is at some angle. When doing tests, you should pick coordinates that are definitely visible, like from center zero to 5, for example.

Bear in mind that the line is only one render pixel wide which is why I suggested to use the pc.Mesh API instead to render your own line as you can control which layer it renders, the thickness etc.

Or what I used to do before was to use a cylinder mesh and scale it.

@LeXXik thanks man I changed it to 0,0,0 to 5,5,5 and I see the line now.

How can I calculate the ranges so when I pull the mouse back it draws a line that way?

@yaustar yes right now I am just trying to make it work like a poc thanks.

Let me see if I got right what you are trying to do: You want to drag the mouse from the ball and away to “charge”, so then you can apply impulse to the ball on release. That impulse will be proportional to the mouse drag length.

if that is so, I think you may be overcomplicating things. To draw a line with renderline you need to provide 2 Vec3 coordinates. To get those I suppose you are using the current ball position and the last position of the mouse after dragging.
The thing is you need to convert the mouse screen coordinate (2d) to a world coordinate (3d), so you’ll probably end up using camera.screenToWorld() to be able to create that last Vec3 (assuming the camera orbits the ball)
That implies the ball will “travel” only inside of a plane parallel to the camera for every shot (like in classic pool game). For example, to shoot at the goal you would have to do it from a side view.

is this what you want?

yes that is exactly what I want. Right now I am getting start position from ball but I can’t get last position of the pointer. It gives me the coodinates from computer screen not from game scene.

@muratg have you looked at the example I’ve posted above?

I am doing the exact same thing, having a fixed point (start point) I am calculating the end point from the mouse pointer using screenToWorld.

Here is the relevant code:

    // Initialise the ray and work out the direction of the ray from the a screen position
    this.cameraEntity.camera.screenToWorld(screenPosition.x, screenPosition.y, this.cameraEntity.camera.farClip, this.ray.direction); 
    this.ray.origin.copy(this.cameraEntity.getPosition());
    this.ray.direction.sub(this.ray.origin).normalize();
    
    var result = this.aabbShape.intersectsRay(this.ray, this.hitPosition);    
1 Like