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

Teleport entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Minfas
Member
Join Date: Dec 2017
Old 11-16-2019 , 09:00   Teleport entity
Reply With Quote #1

Hi,
I am trying to figure out how to teleport a entity (prop_dynamic_override) little bit to left and backwards.
PHP Code:

TeleportEntity
(entityg_fLocationg_fAnglesNULL_VECTOR); 
Adding values to g_fLocation is probably useless because its written as coordinates on the map.

Thank you for help!

Last edited by Minfas; 11-16-2019 at 09:20.
Minfas is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-16-2019 , 10:50   Re: Teleport entity
Reply With Quote #2

Quote:
Originally Posted by Minfas View Post
Hi,
I am trying to figure out how to teleport a entity (prop_dynamic_override) little bit to left and backwards.
PHP Code:

TeleportEntity
(entityg_fLocationg_fAnglesNULL_VECTOR); 
Adding values to g_fLocation is probably useless because its written as coordinates on the map.

Thank you for help!
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", g_fLocation);

g_fLocation[0] += 24.0
g_fLocation[1] += 24.0


TeleportEntity(entity, g_fLocation, g_fAngles, NULL_VECTOR);

Mess with numbers or use negative numbers until you're good.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Minfas
Member
Join Date: Dec 2017
Old 11-16-2019 , 12:07   Re: Teleport entity
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
GetEntPropVector(entity, Prop_Data, "m_vecOrigin", g_fLocation);

g_fLocation[0] += 24.0
g_fLocation[1] += 24.0


TeleportEntity(entity, g_fLocation, g_fAngles, NULL_VECTOR);

Mess with numbers or use negative numbers until you're good.
Yes, this is nice, but when the entity gets spawned rotated 180 degrees on the same place, the position after this teleport will be the same. That's because g_fLocation are coordinates of the map. I need to teleport the enitity relative to itself.

Last edited by Minfas; 11-16-2019 at 12:12.
Minfas is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-16-2019 , 12:24   Re: Teleport entity
Reply With Quote #4

In that case, it will need to be calculated. There are a couple ways to do it, here is a somewhat simple version:
Code:
g_fLocation[0] = (g_fLocation[0] - (10 * Cosine(DegToRad(g_fAngles[1]))));
g_fLocation[1] = (g_fLocation[1] - (10 * Sine(DegToRad(g_fAngles[1]))));
g_fAngles[1]+=90.0;
g_fLocation[0] = (g_fLocation[0] + (10 * Cosine(DegToRad(g_fAngles[1]))));
g_fLocation[1] = (g_fLocation[1] + (10 * Sine(DegToRad(g_fAngles[1]))));
g_fAngles[1]-=90.0;
TeleportEntity(entity, g_fLocation, g_fAngles, NULL_VECTOR);
There is a way to do it in one calculation, but this is accurate enough.
It will move the location backwards relative to the angles.
+90 will rotate left.
Then move forwards (relative to new ang) 10.
Then -90 to return angs then teleport.
Balimbanana is offline
Minfas
Member
Join Date: Dec 2017
Old 11-16-2019 , 13:40   Re: Teleport entity
Reply With Quote #5

Quote:
Originally Posted by Balimbanana View Post
In that case, it will need to be calculated. There are a couple ways to do it, here is a somewhat simple version:
Code:
g_fLocation[0] = (g_fLocation[0] - (10 * Cosine(DegToRad(g_fAngles[1]))));
g_fLocation[1] = (g_fLocation[1] - (10 * Sine(DegToRad(g_fAngles[1]))));
g_fAngles[1]+=90.0;
g_fLocation[0] = (g_fLocation[0] + (10 * Cosine(DegToRad(g_fAngles[1]))));
g_fLocation[1] = (g_fLocation[1] + (10 * Sine(DegToRad(g_fAngles[1]))));
g_fAngles[1]-=90.0;
TeleportEntity(entity, g_fLocation, g_fAngles, NULL_VECTOR);
There is a way to do it in one calculation, but this is accurate enough.
It will move the location backwards relative to the angles.
+90 will rotate left.
Then move forwards (relative to new ang) 10.
Then -90 to return angs then teleport.
I will never understand these math things Anyway, you solved my problem, thank you for help!
Minfas is offline
Stugger
Member
Join Date: Sep 2007
Old 11-17-2019 , 05:03   Re: Teleport entity
Reply With Quote #6

Here's one way to do things like that if you're bad at math like me

Code:
float direction[3];

// Here we get the forward vector of the entity, negate it since we want to move backward and set the distance to move back
GetAngleVectors(g_fAngles, direction, NULL_VECTOR, NULL_VECTOR);
NegateVector(direction);
ScaleVector(direction, FLOAT_UNITS_TO_MOVE_BACK);
AddVectors(g_fLocation, direction, g_fLocation);
						
// Then from the backwards position, get the right vector, negate it since we want to move left and set the distance to move left
GetAngleVectors(g_fAngles, NULL_VECTOR, direction, NULL_VECTOR);
NegateVector(direction);
ScaleVector(direction, FLOAT_UNITS_TO_MOVE_LEFT);
AddVectors(g_fLocation, direction, g_fLocation);
						
TeleportEntity(entity, g_fLocation, g_fAngles, NULL_VECTOR);
Stugger is offline
Reply


Thread Tools
Display Modes

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 12:15.


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