Repository navigation
A3D_SweepSphere
Move a sphere along a segment and find where it first touches something.
Like A3D_RayCast for something with a size: a camera that must not enter walls, or a spot where a thrown object would stop.
native bool:A3D_SweepSphere(
Float:radius,
Float:startX,
Float:startY,
Float:startZ,
Float:endX,
Float:endY,
Float:endZ,
&Float:x,
&Float:y,
&Float:z,
&A3D_HIT:type = A3D_HIT_MAP,
&hitid = 0,
&material = 0,
worldid = -1,
A3D_COLLIDE:flags = A3D_COLLIDE_ALL
);| Parameter | Description | Default |
|---|---|---|
Float:radius |
Radius of the sphere. | |
Float:startX |
Start of its centre on the X axis. | |
Float:startY |
Start on the Y axis. | |
Float:startZ |
Start on the Z axis. | |
Float:endX |
End of its centre on the X axis. | |
Float:endY |
End on the Y axis. | |
Float:endZ |
End on the Z axis. | |
&Float:x |
Centre where it stops on the X axis, or the end when nothing is touched. | |
&Float:y |
Centre on the Y axis. | |
&Float:z |
Centre on the Z axis. | |
&A3D_HIT:type |
What it touched. | A3D_HIT_MAP |
&hitid |
Model of the map object, or the physics object, static object, player, vehicle or actor touched. | 0 |
&material |
Surface of the game touched, see A3D_GetMaterialName. |
0 |
worldid |
Virtual world to look in, or -1 for every world. |
-1 |
A3D_COLLIDE:flags |
What the sphere may touch. | A3D_COLLIDE_ALL |
-
truewhen the sphere touched something. -
falsewhen it reached the end, or the radius is not positive.
A ray has no thickness and slips through gaps a real object would not fit in. A sweep moves a whole sphere along the segment and stops it at the first touch, with x, y and z at its centre then. When nothing is touched, the end of the segment is written and the native returns false, so the point is always usable.
With A3D_COLLIDE_WATER, the sweep also stops where its centre reaches the surface of the water. Everything else follows A3D_RayCast.
Places a camera behind a player without letting it enter a wall.
stock SetCameraBehind(playerid, Float:distance) {
new
Float:x,
Float:y,
Float:z,
Float:angle,
Float:cameraX,
Float:cameraY,
Float:cameraZ
;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, angle);
A3D_SweepSphere(0.3, x, y, z + 0.8, x + distance * floatsin(angle, degrees), y - distance * floatcos(angle, degrees), z + 1.5, cameraX, cameraY, cameraZ, .worldid = GetPlayerVirtualWorld(playerid), .flags = A3D_COLLIDE_MAP | A3D_COLLIDE_STATIC);
SetPlayerCameraPos(playerid, cameraX, cameraY, cameraZ);
SetPlayerCameraLookAt(playerid, x, y, z + 0.8);
}- A3D_RayCast: Find the first thing a segment between two points hits.
- A3D_OverlapSphere: Find everything a sphere overlaps.
- A3D_PredictTrajectory: Follow something thrown, such as a grenade, and find where it first lands.
3DAndreas 0.7.1 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Physics objects
- Model settings
- World queries
- The screen
- Routes
- Navigation mesh
- Map database
- Coming from ColAndreas
- Performance
Reference
Functions