Raycasting::testCapsule: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Raycast from point to point, where the ray has a radius.  
Raycast from point to point, where the ray has a radius.  
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">mp.raycasting.testCapsule(pos1, pos2, radius[, ignoredEntity][, flags]);</syntaxhighlight>
<pre>
mp.raycasting.testCapsule(pos1, pos2, radius, [ignoredEntity], [flags]);
</pre>
 
=== Required Arguments ===
=== Required Arguments ===
*'''pos1:''' Vector3
*'''pos1:''' Vector3
*'''pos2:''' Vector3
*'''pos2:''' Vector3
*'''radius:''' Float
*'''radius:''' Float
*'''ignoreEntity:''' Entity handle or object
*'''ignoreEntity:''' Array of entities handle or object
*'''flags:''' Int
*'''flags:''' Array of ints
 
===Return value===
===Return value===
*'''object:''' position, surfaceNormal, material, entity
*'''object:''' position (Entity Coordinates) , surfaceNormal, material (Entity Model) , entity (Handle)
 
==Example==
==Example==
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{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 25: Line 30:
}
}
});
});
 
</pre>
</syntaxhighlight>
}}
</div>


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

Latest revision as of 17:43, 16 March 2025

Raycast from point to point, where the ray has a radius.

Syntax

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

Required Arguments

  • pos1: Vector3
  • pos2: Vector3
  • radius: Float
  • ignoreEntity: Array of entities handle or object
  • flags: Array of ints

Return value

  • object: position (Entity Coordinates) , surfaceNormal, material (Entity Model) , entity (Handle)

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.testCapsule(startPosition, endPosition, 0.5);
	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