choky10 0 Posted March 8, 2020 Share Posted March 8, 2020 Hello i have this code for my raycast.cpp: But when i hit a entity with the IntersectOptions on int 12. My game crash any idea why? I use like this: if (features::activateRaycast) { Entity target; Vector3 camPos = Position(); Vector3 camDir = DirectionFromScreenCentre(); auto ray = RaycastResult::Raycast(camPos, camDir, 20000.0f, IntersectOptions::Peds1, features::myPed()); if (ray.DidHitEntity()) { auto hitEntity = ray.HitEntity(); printf("Entity id: %d", hitEntity); } } Raycast.cpp RaycastResult::RaycastResult() : mResult(0), mDidHit(false) { } RaycastResult::RaycastResult(const RaycastResult& handle) : mResult(handle.mResult), mDidHit(handle.mDidHit), mHitEntity(handle.mHitEntity), mHitCoords(handle.mHitCoords), mSurfaceNormal(handle.mSurfaceNormal) { } RaycastResult::RaycastResult(int handle) { int hitsomething = 0; int enthandle = 0; Vector3 hitCoords, surfaceNormal; this->mResult = SHAPETEST::GET_SHAPE_TEST_RESULT(handle, &hitsomething, &hitCoords, &surfaceNormal, &enthandle); this->mDidHit = hitsomething != 0; this->mHitCoords = hitCoords; this->mSurfaceNormal = surfaceNormal; if (ENTITY::DOES_ENTITY_EXIST(enthandle) && (ENTITY::IS_ENTITY_A_PED(enthandle) || ENTITY::IS_ENTITY_A_VEHICLE(enthandle) || ENTITY::IS_ENTITY_AN_OBJECT(enthandle))) { this->mHitEntity = enthandle; } else { this->mHitEntity = 0; } } int RaycastResult::Result() { return this->mResult; } bool RaycastResult::DidHitEntity() { return mHitEntity != 0; } bool RaycastResult::DidHitAnything() { return this->mDidHit; } Entity RaycastResult::HitEntity() { return this->mHitEntity; } Vector3 RaycastResult::HitCoords() { return this->mHitCoords; } Vector3 RaycastResult::SurfaceNormal() { return this->mSurfaceNormal; } RaycastResult RaycastResult::Raycast(const Vector3& source, const Vector3& target, IntersectOptions options, Entity ignoreEntity) { return RaycastResult(SHAPETEST::_START_SHAPE_TEST_RAY(source.x, source.y, source.z, target.x, target.y, target.z, static_cast<int>(options), ignoreEntity, 7)); } RaycastResult RaycastResult::Raycast(const Vector3& source, const Vector3& direction, float maxDistance, IntersectOptions options, Entity ignoreEntity) { Vector3 target = source + (direction * maxDistance); return RaycastResult(SHAPETEST::_START_SHAPE_TEST_RAY(source.x, source.y, source.z, target.x, target.y, target.z, static_cast<int>(options), ignoreEntity, 7)); } Quote Link to comment Share on other sites More sharing options...
LMS 674 Posted March 8, 2020 Share Posted March 8, 2020 Just so I understand you correctly, it only crashes if your hit test hits an actual entity, otherwise it works fine? Quote Link to comment Share on other sites More sharing options...
Lambda 23 Posted March 8, 2020 Share Posted March 8, 2020 12 is not a bitflag and as far as i know the option is a bitflag. Quote Link to comment Share on other sites More sharing options...
LMS 674 Posted March 8, 2020 Share Posted March 8, 2020 2 hours ago, Lambda said: 12 is not a bitflag and as far as i know the option is a bitflag. It might require bitflags but 12 is 1100b so it would just mean flag 3 and flag 4 are set. Quote Link to comment Share on other sites More sharing options...
Lambda 23 Posted March 8, 2020 Share Posted March 8, 2020 1 hour ago, LMS said: It might require bitflags but 12 is 1100b so it would just mean flag 3 and flag 4 are set. Thats true but multiflag caused alot headache in gta iv/v for me back in the days so i always avoid them, tested with his settings and they work fine for peds. Would be interesting to know if it crashes for him with any other flags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.