Sign in to follow this  
Geramy92

[Client JS] Clicksystem / Raycast Issue

Recommended Posts

Hey there,

I am trying currently to implement a simple click system. Just to explain my goal: I want for example that a player can click on an ATM (from original map - no spawned object) and a UI opens.

My code currently get's triggered by the playerclick event , but the player click event doesn't return an entity. So I thought, I could use Raycast to get the clicked object. But result of it is just a number.

Here my Question: What number is that and can this converted somehow to an entity, to change for example alpha (as debug) or to get the model hash of it?

 

Here my current code to maybe understand my problem a bit better:

mp.events.add('click', (x, y, upOrDown, leftOrRight) => {
    let pos3d = mp.game.graphics.screen2dToWorld3d([x, y]);
    const camera = mp.cameras.new("gameplay"); // gets the current gameplay camera
    let position = camera.getCoord();

    const end = lerp(position, pos3d, 5);
    //@ts-ignore
    const result = mp.raycasting.testPointToPoint(position, end, [mp.players.local]);
  
  	// here I have the problem:  result.entity is a number in case of a world object....	
  
    mp.events.callRemote('playerClick', x, y, upOrDown, leftOrRight, result ? result.entity : null);
});

 

Share this post


Link to post
Share on other sites

Okay, I found a solution. Just for people that have maybe same problem:

Thanks to Yoe on Discord, I know now that I can use simply entity natives for that and use the number result directly as entity for that natives.
So that I don't need Entity object for now :)

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   1 member