Pilatus Posted November 18, 2019 Share Posted November 18, 2019 How to get the position of the object returned by testPointToPoint? const camera = mp.cameras.new("gameplay"); // gets the current gameplay camera let position = camera.getCoord(); // grab the position of the gameplay camera as Vector3 let direction = camera.getDirection(); // get the forwarding vector of the direction you aim with the gameplay camera as Vector3 let farAway = new mp.Vector3((direction.x * distance) + (position.x), (direction.y * distance) + (position.y), (direction.z * distance) + (position.z)); // calculate a random point, drawn on a invisible line between camera position and direction (* distance) let object = mp.raycasting.testPointToPoint(position, farAway, [1, 16]); Got the code from here: https://wiki.rage.mp/index.php?title=Raycasting::testPointToPoint Link to comment Share on other sites More sharing options...
SkyLake Posted November 18, 2019 Share Posted November 18, 2019 If the object is not undefined, you should get the object by its handle if its created by mp.objects.new. let raycast = mp.raycasting.testPointToPoint(position, farAway, [1, 16]); // Your valid raycasted object if (raycast && raycast.entity.handle) { let object = mp.objects.atHandle(raycast.entity.handle); // You'll get the object if you created it via mp.objects.new } Otherwise use its handle to use other object functions. In case you need its model you can do let raycast = mp.raycasting.testPointToPoint(position, farAway, [1, 16]); // Your valid raycasted object if (raycast && raycast.entity.model) { let objectModel = raycast.entity.model; // Do what you want with it } Link to comment Share on other sites More sharing options...
Kar Posted November 18, 2019 Share Posted November 18, 2019 15 hours ago, SkyLake said: If the object is not undefined, you should get the object by its handle if its created by mp.objects.new. let raycast = mp.raycasting.testPointToPoint(position, farAway, [1, 16]); // Your valid raycasted object if (raycast && raycast.entity.handle) { let object = mp.objects.atHandle(raycast.entity.handle); // You'll get the object if you created it via mp.objects.new } Otherwise use its handle to use other object functions. In case you need its model you can do let raycast = mp.raycasting.testPointToPoint(position, farAway, [1, 16]); // Your valid raycasted object if (raycast && raycast.entity.model) { let objectModel = raycast.entity.model; // Do what you want with it } Isn't the handle returned by `raycast.entity` alone? No `.handle` property? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now