Raised This Month: $ Target: $400
 0% 

Origin based on where the player looks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-15-2012 , 09:00   Origin based on where the player looks
Reply With Quote #1

How do I move the origin by 100.0 depending on where the player looks? I cannot add 100 to X or Y origin, because it may be 100 to his back or side.
Backstabnoob is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-15-2012 , 09:11   Re: Origin based on where the player looks
Reply With Quote #2

did you even search before posting?
https://forums.alliedmods.net/showthread.php?t=93773
jimaway is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-15-2012 , 09:21   Re: Origin based on where the player looks
Reply With Quote #3

Yes I do, that code is not what I'm looking for though. I could have explained better.

I mean on ground - if the player's origin is x = 1000, y = 1000 and he's turned to the X axis, I need to get x = 1100 and y = 1000 origin. I don't know how to calculate it. Z axis cannot be taken in account.

Last edited by Backstabnoob; 09-15-2012 at 09:25.
Backstabnoob is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-15-2012 , 09:30   Re: Origin based on where the player looks
Reply With Quote #4

what if player is looking straight between x and y axis? (at 45 degrees angle)
jimaway is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-15-2012 , 09:36   Re: Origin based on where the player looks
Reply With Quote #5

His origin + 100 depending on the angle he's aiming at.
Attached Thumbnails
Click image for larger version

Name:	paint skills.png
Views:	152
Size:	14.4 KB
ID:	109471  

Last edited by Backstabnoob; 09-15-2012 at 09:41.
Backstabnoob is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-15-2012 , 09:46   Re: Origin based on where the player looks
Reply With Quote #6

use the code in the link i gave you, just dont change z origin?

Code:
new pOrigin[3],tOrigin[3] get_user_origin(id,pOrigin) get_user_origin(id,tOrigin,3) tOrigin[2] = pOrigin[2] if( get_distance(pOrigin, tOriign) > 100 ) {     new vector[3];     vector[0] = tOrigin[0] - pOrigin[0];     vector[1] = tOrigin[1] - pOrigin[1];     vector[2] = tOrigin[2] - pOrigin[2];         new Float:fVector[3];     IVecFVec(vector, fVector);         new Float:length = vector_length(fVector);         fVector[0] = fVector[0] / length * 100;     fVector[1] = fVector[1] / length * 100;     fVector[2] = fVector[2] / length * 100;         FVecIVec(fVector, vector);         tOrigin[0] = pOrigin[0] + vector[0];     tOrigin[1] = pOrigin[1] + vector[1];     tOrigin[2] = pOrigin[2] + vector[2]; } set_user_origin(id, tOrigin)

something like this

Last edited by jimaway; 09-15-2012 at 09:53.
jimaway is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-15-2012 , 09:49   Re: Origin based on where the player looks
Reply With Quote #7

No, it doesn't work the way I need at all.
Backstabnoob is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 09-15-2012 , 09:59   Re: Origin based on where the player looks
Reply With Quote #8

how do you need it then lol? it does what the picture shows
jimaway is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-15-2012 , 11:01   Re: Origin based on where the player looks
Reply With Quote #9

get_user_origin(id, origin, mode=3)

Notes:

Modes:

0 - current position.
1 - position from eyes (weapon aiming).
2 - end position from player position.
3 - end position from eyes (hit point for weapon).
4 - position of last bullet hit (only CS).


That what you're looking for? granted, it won't be 100 units, but you could trim it down by using mode 1 and 3. Though this will raise your position a bit because its from the eyes, not the ground/feet.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
fearAR
Veteran Member
Join Date: Oct 2010
Old 09-17-2012 , 17:09   Re: Origin based on where the player looks
Reply With Quote #10

PHP Code:

new Float:fOrigin], Float:fViewOfs], Float:fViewAngles], Float:fEndOrigin], Float:fMagnitude;

pevidpev_originfOrigin ); // Obtain user origin
pevidpev_view_ofsfViewOfs ); // Obtain user eye position

fOrigin] += fViewOfs]; // Add eye position to origin
fOrigin] += fViewOfs];
fOrigin] += fViewOfs];

pevidpev_v_anglefViewAngles ); // Obtain View angles ( pitch yaw roll ) of the user camera
engfuncEngFunc_MakeVectorsfViewAngles ); // Make vectors from the viewangles
global_getglb_v_forwardfViewAngles ); // Obtain vector relationed FORWARD

fMagnitude floatsqroot( ( fViewAngles] * fViewAngles] ) + ( fViewAngles] * fViewAngles] ) + ( fViewAngles] * fViewAngles] ) ); // Obtain magnitude from forward viewangles vector

fViewAngles] /= fMagnitude// Obtain the normalized vector
fViewAngles] /= fMagnitude;
fViewAngles] /= fMagnitude;

fMagnitude 100.0// Change magnitude

fViewAngles] *= fMagnitude// advance the normalized vector by magnitude = 100.0
fViewAngles] *= fMagnitude;
fViewAngles] *= fMagnitude;

fEndOrigin] = fOrigin] + fViewAngles]; // Add Viewing angles direction to user origin
fEndOrigin] = fOrigin] + fViewAngles];
fEndOrigin] = fOrigin] + fViewAngles]; 
Greetings.
__________________
~~~~ NPC AI ~~~~

[ Pathfinding - OK ]
[ Citizen AI - OK ]
[ Handle Weapons - --- ]
fearAR is offline
Send a message via MSN to fearAR
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 08:16.


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