Raised This Month: $51 Target: $400
 12% 

How to get the angle direction between two entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 10-04-2023 , 09:50   How to get the angle direction between two entities
Reply With Quote #1

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 to show you what I mean



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
Attached Files
File Type: sp Get Plugin or Get Source (pet_test.sp - 55 views - 10.3 KB)
File Type: smx pet_test.smx (10.9 KB, 33 views)
__________________

Last edited by alasfourom; 10-04-2023 at 15:41.
alasfourom is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 10-05-2023 , 18:25   Re: How to get the angle direction between two entities
Reply With Quote #2

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.
__________________
Rohanlogs is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 10-05-2023 , 23:46   Re: How to get the angle direction between two entities
Reply With Quote #3

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



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.
__________________

Last edited by alasfourom; 10-06-2023 at 04:25.
alasfourom is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 10-06-2023 , 00:02   Re: How to get the angle direction between two entities
Reply With Quote #4

After much consideration, tilting or adjusting the angle is not a good method, I need as you said to change Z pos.
__________________

Last edited by alasfourom; 10-06-2023 at 04:26.
alasfourom is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 10-06-2023 , 07:10   Re: How to get the angle direction between two entities
Reply With Quote #5

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.

Last edited by kadet.89; 10-06-2023 at 07:21.
kadet.89 is offline
Send a message via Skype™ to kadet.89
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 10-06-2023 , 09:28   Re: How to get the angle direction between two entities
Reply With Quote #6

Quote:
Originally Posted by kadet.89 View Post
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
__________________
alasfourom is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-06-2023 , 13:35   Re: How to get the angle direction between two entities
Reply With Quote #7

maybe this plugin can give you some hints https://forums.alliedmods.net/showthread.php?p=2768940
__________________
Marttt is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 10-06-2023 , 15:31   Re: How to get the angle direction between two entities
Reply With Quote #8

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
kadet.89 is offline
Send a message via Skype™ to kadet.89
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 10-07-2023 , 00:41   Re: How to get the angle direction between two entities
Reply With Quote #9

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
__________________

Last edited by alasfourom; 10-07-2023 at 00:41.
alasfourom is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:01.


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