Get direction player is moving relative to other player
I'm trying to make fist combat a little more complex in csgo (rather than just plain old flat damage every time). One of the things I want to do is make it so that when you punch someone, your damage increases relative to your speed if you were moving toward them, and decreases relative to your speed if you were moving away from them. I will be using SDKHook_OnTakeDamage to check if attacker is moving toward or away from victim, and how quickly the attacker is moving.
I'm not certain on the next step I would take from here. The picture below is my attempt at kinda showing what I plan to do. Blue punches red. Green arrow represents the direction they are running. https://i.imgur.com/EgoyLhY.png I think what I need to do is create a line between the attacker's origin and the victim's origin. Then, I would get the line perpendicular to this one. This perpendicular line represents the 100% line (no increase or decrease in damage). Next, I would create another line using the attacker's velocity vector. This line would start from the attacker's origin. From here, I need to do something with angles to determine how I increase/decrease damage, but I am not too sure on how to go about this. https://i.imgur.com/wjEmX6n.png |
Re: Get direction player is moving relative to other player
This should be easily doable with a simple dot product between vectors a and b, where vector a is a unit vector in the direction from attacker's origin to victim's origin and b is a unit vector in the direction of attacker's velocity. You can think of a dot product as a projection of one vector onto the another one, like in this pic from Wikipedia's page on dot product:
https://upload.wikimedia.org/wikiped...roduct.svg.png. If the a and b are parallel (that is, the attacker is moving towards the victim) then the dot product would be 1, and -1 if moving away (a and b are negatives of each other). Everything in between is, well, in between. To get a gradient between 0.5 and 1.5 it should be as simple as 1 + 0.5 * dot_product. |
Re: Get direction player is moving relative to other player
Thanks for your advice.
I currently have this, but I am getting a number in the thousands. PHP Code:
|
Re: Get direction player is moving relative to other player
Quote:
While you may be thinking of velocity as this: https://i.imgur.com/aL29KL1.png In actuality it's just this: https://i.imgur.com/lUeaMfo.png |
Re: Get direction player is moving relative to other player
Awesome, changed it to the snippet below and it works perfectly.
Thank you so much for your explanation! I feel a bit silly for what I did with the AddVectors part - I started with a velocity vector, used it to get the next position, and then used the two positions to just get the same velocity vector back :oops: PHP Code:
(note that the damage in chat is wrong because armor appears to eat 50% of damage). |
Re: Get direction player is moving relative to other player
If I understand your armour issue correctly, you should be able to use a OnTakeDamageAlive hook to get the real damage applied to the player.
|
All times are GMT -4. The time now is 06:37. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.