CrAzY_-7865 Posted June 15, 2019 Share Posted June 15, 2019 Hi everyone I wanted to asks, how can I detect when my character is near an object? If my character touches the door (and the door opens), it will automatically be teleported to a specific location. I have no idea how to detect if it touches the door (it would be better when it opens). Something like a portal gun. does anyone have any ideas? Link to comment Share on other sites More sharing options...
Jitnaught Posted June 15, 2019 Share Posted June 15, 2019 C++: ENTITY::IS_ENTITY_TOUCHING_ENTITY C#: Game.Player.Character.IsTouching(entityHere) If you don't know the entity or this doesn't work, you can get the distance between to coordinates: C++: MISC::GET_DISTANCE_BETWEEN_COORDS C#: Game.Player.Character.Position.DistanceTo(position) CrAzY_-7865 1 Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 15, 2019 Author Share Posted June 15, 2019 (edited) 5 hours ago, Jitnaught said: C++: ENTITY::IS_ENTITY_TOUCHING_ENTITY C#: Game.Player.Character.IsTouching(entityHere) If you don't know the entity or this doesn't work, you can get the distance between to coordinates: C++: MISC::GET_DISTANCE_BETWEEN_COORDS C#: Game.Player.Character.Position.DistanceTo(position) Vector3 MyCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), !ENTITY::IS_ENTITY_DEAD(PLAYER::PLAYER_PED_ID())); Vector3 EntityCoords = ENTITY::GET_ENTITY_COORDS(EntitySpawned, !ENTITY::IS_ENTITY_DEAD(EntitySpawned)); float DistanceOfEntity = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(MyCoords.x, MyCoords.y, MyCoords.z, EntityCoords.x, EntityCoords.y, EntityCoords.z, false); if (DistanceOfEntity != 0){ notify("You're close to the entity!"); }else{ notify("You're still too far away."); } Jitnaught something like this? Edited June 15, 2019 by CrAzY_-7865 Link to comment Share on other sites More sharing options...
Jitnaught Posted June 15, 2019 Share Posted June 15, 2019 Looks pretty good, although the distance will probably never be exactly zero. < 0.5f or similar would be best. Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 16, 2019 Author Share Posted June 16, 2019 23 hours ago, Jitnaught said: Looks pretty good, although the distance will probably never be exactly zero. < 0.5f or similar would be best. Yes, I noticed it. The only problem is that I don't understand why it runs the function in a loop. In this case, teleportation. I tried to insert a break / return, but nothing. Link to comment Share on other sites More sharing options...
Jitnaught Posted June 16, 2019 Share Posted June 16, 2019 I'm not sure what you mean. Since you're using C++, you are running the function in the while(true) loop. Post the code so we can help, or PM me it. Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 16, 2019 Author Share Posted June 16, 2019 (edited) 4 minutes ago, Jitnaught said: I'm not sure what you mean. Since you're using C++, you are running the function in the while(true) loop. Post the code so we can help, or PM me it. Vector3 MyCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), !ENTITY::IS_ENTITY_DEAD(PLAYER::PLAYER_PED_ID())); Vector3 EntityCoords = ENTITY::GET_ENTITY_COORDS(EntitySpawned, !ENTITY::IS_ENTITY_DEAD(EntitySpawned)); float DistanceOfEntity = GAMEPLAY::GET_DISTANCE_BETWEEN_COORDS(MyCoords.x, MyCoords.y, MyCoords.z, EntityCoords.x, EntityCoords.y, EntityCoords.z, false); if (DistanceOfEntity != 0){ //teleport(PLAYER::PLAYER_PED_ID(), X, Y, Z, H);//but executes this function in loop }else{ notify("You're still too far away."); } Edited June 16, 2019 by CrAzY_-7865 Link to comment Share on other sites More sharing options...
Jitnaught Posted June 16, 2019 Share Posted June 16, 2019 (edited) The distance will almost never be exactly 0, so (DistanceOfEntity != 0) will basically always return true, which in turn means you will be teleporting forever. Edited June 16, 2019 by Jitnaught Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 16, 2019 Author Share Posted June 16, 2019 20 minutes ago, Jitnaught said: The distance will almost never be exactly 0, so (DistanceOfEntity != 0) will basically always return true, which in turn means you will be teleporting forever. So if I remove "! = 0", with a return / break, will not execute no longer perform the function in a loop? Link to comment Share on other sites More sharing options...
Jitnaught Posted June 16, 2019 Share Posted June 16, 2019 Replace it with (DistanceOfEntity < 0.5f) Then it should only teleport when you are within 0.5 units. When you teleport away, you should be farther than 0.5 units, and the loop will end. CrAzY_-7865 1 Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 25, 2019 Author Share Posted June 25, 2019 On 6/17/2019 at 1:59 AM, Jitnaught said: Replace it with (DistanceOfEntity < 0.5f) Then it should only teleport when you are within 0.5 units. When you teleport away, you should be farther than 0.5 units, and the loop will end. How i can get if i touch the cell gate? The method I did above, unfortunately does not work, only works with the entities I spawned. Link to comment Share on other sites More sharing options...
CrAzY_-7865 Posted June 29, 2019 Author Share Posted June 29, 2019 Someone? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now