Raycasting::TestPointToPoint: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This function casts a ray from Point1 to Point2 and returns the position and entity of what's in the way, or undefined if the way is cleared.<br><br>Flags are intersection bit flags.  They tell the ray what to care about and what not to care about when casting. Passing -1 will intersect with everything, presumably.<br><br>Flags:<br>1: Intersect with map<br>2: Intersect with vehicles (used to be mission entities?) (includes train)<br>4: Intersect with peds? (same as 8)<br>8: Intersect with peds? (same as 4)<br>16: Intersect with objects<br>32: Unknown<br>64: Unknown<br>128: Unknown<br>256: Intersect with vegetation (plants, coral. trees not included)<br><br>NOTE: Raycasts that intersect with mission_entites (flag = 2) has limited range and will not register for far away entites. The range seems to be about 30 metres.  
This function casts a ray from Point1 to Point2 and returns the position and entity of what's in the way, or undefined if the way is cleared.<br><br>Flags are intersection bit flags.  They tell the ray what to care about and what not to care about when casting. Passing -1 will intersect with everything, presumably.<br><br>Flags:<br>1: Intersect with map<br>2: Intersect with vehicles (used to be mission entities?) (includes train)<br>4: Intersect with peds? (same as 8)<br>8: Intersect with peds? (same as 4)<br>16: Intersect with objects<br>32: Unknown<br>64: Unknown<br>128: Unknown<br>256: Intersect with vegetation (plants, coral. trees not included)<br><br>NOTE: Raycasts that intersect with mission_entites (flag = 2) has limited range and will not register for far away entites. The range seems to be about 30 metres.  
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">mp.raycasting.testPointToPoint(pos1, pos2[, ignoredEntity][, flags]);</syntaxhighlight>
<pre>
mp.raycasting.testPointToPoint(pos1, pos2[, ignoredEntity][, flags]);
</pre>
 
=== Required Arguments ===
=== Required Arguments ===
*'''pos1:''' Vector3
*'''pos1:''' Vector3
Line 7: Line 11:
*'''ignoreEntity:''' Entity handle or object
*'''ignoreEntity:''' Entity handle or object
*'''flags:''' array
*'''flags:''' array
===Return value===
===Return value===
*'''object'''
*'''object'''
==Example==
==Example==
<div class="header" style="background-color: #AE4040; color: #FFFFFF; border: 2px solid #AE4040;">
{{ClientsideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Client-Side</b></div>
<pre>
<syntaxhighlight lang="javascript" highlight="5">
mp.events.add('render', () => {
mp.events.add('render', () => {
const startPosition = player.getBoneCoords(12844, 0.5, 0, 0);
const startPosition = player.getBoneCoords(12844, 0.5, 0, 0);
Line 24: Line 29:
}
}
});
});
 
</pre>
</syntaxhighlight>
}}
</div>


==See also==
==See also==
{{Worldprobe_s_function_c}}
{{Worldprobe_s_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]

Latest revision as of 23:02, 26 October 2018

This function casts a ray from Point1 to Point2 and returns the position and entity of what's in the way, or undefined if the way is cleared.

Flags are intersection bit flags. They tell the ray what to care about and what not to care about when casting. Passing -1 will intersect with everything, presumably.

Flags:
1: Intersect with map
2: Intersect with vehicles (used to be mission entities?) (includes train)
4: Intersect with peds? (same as 8)
8: Intersect with peds? (same as 4)
16: Intersect with objects
32: Unknown
64: Unknown
128: Unknown
256: Intersect with vegetation (plants, coral. trees not included)

NOTE: Raycasts that intersect with mission_entites (flag = 2) has limited range and will not register for far away entites. The range seems to be about 30 metres.

Syntax

mp.raycasting.testPointToPoint(pos1, pos2[, ignoredEntity][, flags]);

Required Arguments

  • pos1: Vector3
  • pos2: Vector3
  • ignoreEntity: Entity handle or object
  • flags: array

Return value

  • object

Example

Client-Side
mp.events.add('render', () => {
	const startPosition = player.getBoneCoords(12844, 0.5, 0, 0);
	const endPosition = new mp.Vector3(0, 0, 75);

	const hitData = mp.raycasting.testPointToPoint(startPosition, endPosition);
	if (!hitData) {
		mp.game.graphics.drawLine(startPosition.x, startPosition.y, startPosition.z, endPosition.x, endPosition.y, endPosition.z, 255, 255, 255, 255); // Is in line of sight
	} else {
		mp.game.graphics.drawLine(startPosition.x, startPosition.y, startPosition.z, endPosition.x, endPosition.y, endPosition.z, 255, 0, 0, 255); // Is NOT in line of sight
	}
});

See also

Template:Worldprobe s function c