AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to get the angle direction between two entities (https://forums.alliedmods.net/showthread.php?t=344115)

alasfourom 10-04-2023 09:50

How to get the angle direction between two entities
 
2 Attachment(s)
Hello guys

Trying to solve an issue where I can't exactly adjust an entity angle direction to my position.

You can see this drawing skills of mine :bacon: to show you what I mean

https://i.ibb.co/MNm2ZSN/Untitled.png

I found a snippet in the modders community to adjust the entity angle to always face my direction but not when it comes to height difference

PHP Code:

// client
float client_pos[3];
GetClientAbsOrigin(clientclient_pos);
    
// pet
float pet_ang[3], pet_pos[3];
GetEntPropVector(entityProp_Data"m_vecOrigin"pet_pos);
GetEntPropVector(entityProp_Data"m_angRotation"pet_ang);

// adjust pet direction to my position
float distX client_pos[0] - pet_pos[0];
float distY client_pos[1] - pet_pos[1];
pet_ang[1] = (ArcTangent2(distYdistX) * 180) / 3.14

Video to show you my issue - YouTube


I Uploaded a test version, using TR_DidHit() to detect ground and attach it to it. You will notice some issues when going to different level surface.

Requires: Left4Dhooks

Video showing the test version - YouTube

If anyone has a solution, that would be great

Thanks

Rohanlogs 10-05-2023 18:25

Re: How to get the angle direction between two entities
 
Hey. Its a nice drawing, but what's the actual problem?

You say "I can't exactly adjust an entity angle direction to my position", also the title of this post suggests there's a problem with angles, but the linked video shows a problem with Z position. And the 'test version' video doesn't have this problem. In the test version video with the TR_DidHit which I'm now assuming is the code you posted, it seems to work fine ish? When you say 'You will notice some issues', I am not sure what you mean. So where exactly is the problem? What is your desired behavior?

I can see however the odd teleporting from 1:22 forward, which is caused by this:

PHP Code:

// Start running
if (client_pos[2] - pet_pos[2] > 100.0SetAbsOrigin(g_iPet_Entity[client], client_pos); // if lost, teleport back
else SetAbsOrigin(g_iPet_Entity[client], out); // otherwise, we push it 

Here you're checking if the client is directly above the pet more than 100 units, this causes the pet to now teleport to the player when the player climbs a surface or jumps high enough. Which is probably not intended.

My suggestions are if you want to teleport the pet back if it gets lost, you should check it somehow else. Perhaps create a function to get the distance from the pet to the player, if the distance gets larger than X units, then teleport the pet back. Or think of something better. Is this even required? Can the pet actually get lost?

GetDistanceToFloor() doesn't actually get the "distance to the floor". It returns the Z position of where the ray hits, which, looking at the angle should be the ground. So a more proper name would be something like GetGroundPosition().

If you want the pet to have some 'gravity' instead of teleporting instanly to ground level, you could implement a slower increase/decrease of the Z position, and add a jumping animation when increasing it, if such animation exists.

alasfourom 10-05-2023 23:46

Re: How to get the angle direction between two entities
 
Quote:

the title of this post suggests there's a problem with angles, but the linked video shows a problem with Z position.
No, I meant the angle, if I can tilt it to face the next pos, I think would be it.

Since currently what I do, is pushing the prop_dynamic from point 1 to point 2, then point 2 to point 3 etc to achieve an ideal movements. But if we kept adjusting the Z pos every time, it wouldn't be ideal.

See this image, I want to tilt it to my next pos, and then push it, instead of adjusting the Z pos

https://i.ibb.co/02Q6fdB/test.png

Quote:

If you want the pet to have some 'gravity' instead of teleporting instantly to ground level, you could implement a slower increase/decrease of the Z position, and add a jumping animation when increasing it, if such animation exists.
Hmmm I guess I will try to detect next Z pos step and compares it to current Z pos, then decrease or increase based on the height difference.

alasfourom 10-06-2023 00:02

Re: How to get the angle direction between two entities
 
After much consideration, tilting or adjusting the angle is not a good method, I need as you said to change Z pos.

kadet.89 10-06-2023 07:10

Re: How to get the angle direction between two entities
 
I may guess that you are trying to implement a sort of NPC? If yes, there is a "monster_generic" entity available in most source engine games which can walk and overcome some dynamic obstacles (barrels and boxes). You could spawn one with "zombie classic" model from HL2 and see if it meets your requirements.
https://developer.valvesoftware.com/...onster_generic

On the second level of ze_Castlevania_p1_7 there are knights with swords which walk around and attack players (you can check them on youtube). Implemented with pure mapping.
At the beginning of the first level of ze_best_korea_v1 there is a solder who can walk around, jump and attack the players.

alasfourom 10-06-2023 09:28

Re: How to get the angle direction between two entities
 
Quote:

Originally Posted by kadet.89 (Post 2811196)
I may guess that you are trying to implement a sort of NPC? If yes, there is a "monster_generic" entity available in most source engine games which can walk and overcome some dynamic obstacles (barrels and boxes). You could spawn one with "zombie classic" model from HL2 and see if it meets your requirements.
https://developer.valvesoftware.com/...onster_generic

On the second level of ze_Castlevania_p1_7 there are knights with swords which walk around and attack players (you can check them on youtube). Implemented with pure mapping.
At the beginning of the first level of ze_best_korea_v1 there is a solder who can walk around, jump and attack the players.

monster_generic is a point entity present in all games except the Left 4 Dead games. It's a generic NPC. Does not work in CSS and CSGO.

Sadly I'm using L4D2 for this

Marttt 10-06-2023 13:35

Re: How to get the angle direction between two entities
 
maybe this plugin can give you some hints https://forums.alliedmods.net/showthread.php?p=2768940

kadet.89 10-06-2023 15:31

Re: How to get the angle direction between two entities
 
You cold check then how the npc implemented in ze_best_korea_v1 and ze_Castlevania_p1_7. They are based on prop_dynamic entities combined with sets of triggers. All of it can be implemented with coding, I believe.
And there is this NPC extension: https://forums.alliedmods.net/showthread.php?t=335156

alasfourom 10-07-2023 00:41

Re: How to get the angle direction between two entities
 
Thank you guys, I have seen and read all these scripts which all have helped me build some ideas to improve it. Still working on it, hopefully it becomes as I plan. Thanks a lot


All times are GMT -4. The time now is 14:57.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.