I have this Sphere that I created and I want rockets to reflect off of the surface of the sphere. The thing is I can't use on start touch with the rocket and have it reflect off because there isn't technically a surface. But what I coded is when the rocket gets within the sphere radius then do the reflect but it doesn't reflect properly. (I literally just copied and pasted the code from Rocket Bounce)
PHP Code:
public Action:Timer_Rocket(Handle:timer, any:entref)
{
new entity = EntRefToEntIndex(entref);
if(IsValidEntity(entity))
{
decl Float:vOrigin[3];
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", vOrigin);
decl Float:vAngles[3];
GetEntPropVector(entity, Prop_Data, "m_angRotation", vAngles);
decl Float:vVelocity[3];
GetEntPropVector(entity, Prop_Data, "m_vecAbsVelocity", vVelocity);
new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TEF_ExcludeEntity, entity);
if(!TR_DidHit(trace))
{
CloseHandle(trace);
return Plugin_Continue;
}
decl Float:vNormal[3];
TR_GetPlaneNormal(trace, vNormal);
CloseHandle(trace);
new Float:dotProduct = GetVectorDotProduct(vNormal, vVelocity);
ScaleVector(vNormal, dotProduct);
ScaleVector(vNormal, 2.0);
decl Float:vBounceVec[3];
SubtractVectors(vVelocity, vNormal, vBounceVec);
decl Float:vNewAngles[3];
GetVectorAngles(vBounceVec, vNewAngles);
if(GetVectorDistance(coord, vOrigin) < sphereRadius + 5.0) //Hitting Sphere
{
TeleportEntity(entity, NULL_VECTOR, vNewAngles, vBounceVec);
}
}
return Plugin_Continue;
}
__________________