UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Moving an object relative to players facing direction.

broken avatar :(
Created 8 years ago
by Archaicvirus
0 Members and 1 Guest are viewing this topic.
2,890 views
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
Signature
Let he who has not sinned cast the first stone.
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
What I'm trying to do is is a moveto on an entity, which I can do easily, but the problem I'm having is figuring out how to keep the entity in front of the player at all times. For example:
Code Snippet
Plaintext
little_shoulder_devil()
{
x = ("50"); // 50 units in front of players face
y = ("50"); // 50 units to the right of player
z = ("50"); // 50 units above players shoulder
}

guardian_follow()
{
while(flag(var))
{
if(life <= 0)
{
ent moveto(player.origin+(x,y,z));
wait .05;
}
else
{
thread cooldown();
break;
}
}
}
(


This is not my exact code but a mockup of what I'm trying to do. I noticed the geteye() function in the ugx script references, but to my understanding that gets the angles of the player's facing direction. This is where my problem is, I can't figure out how to adjust the moveto coordinates relative to the player's facing angle. For example, if north is +x, and south is -x, and so on for y and z, how can I convert the facing direction to a relative offset of the player. If anyone could give me some suggestions I would greatly appreciate it, as well as give you credit in a mutual project I'm working on. Hopefully I explained my intentions clearly, if not let me know and I'll elaborate.
Marked as best answer by Archaicvirus 8 years ago
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
Self getanglestoforward() * value
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Thanks, I will try this when I get off work.

Double Post Merge: August 13, 2016, 04:16:21 am
So in your example,
Self getanglestoforward() * value

I was getting an unknown function with that, so I searched some of vanilla scripts and found anglesToForward() which I'm assuming is what you meant. However, I don't understand the syntax as shown in the ugx scripting reference:
Code Snippet
Plaintext
forward = anglesToForward(forward);

It seems redundant to me looking at it. Why is a variable being defined and then sent in the same line?
I tried anyways with every permutation of the syntax I could think of, but trial and error yielded no results :(
This is the last code I tried, which compiles fine but nothing is printing:
Code Snippet
Plaintext
test_angles_and_print();
{
while(1)
{
pangles = players getPlayerAngles();
f = anglesToForward(pangles);
u = anglesToUp(pangles);
r = anglesToRight(pangles);
if(isdefined(pangles))
iprintln(pangles,f,u,r);
wait .5;
}
}
Any further help is greatly appreciated. In the meantime I'll keep trying, and I'll update if I have any luck.

Double Post Merge: August 13, 2016, 04:45:43 am
The code I posted, I drafted just for an example to be short, and forgot to define "players". So to make it easier I'll loan you the full code I'm working on that I'm using it in:
Code Snippet
Plaintext
#include common_scripts\utility; 
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\ugx_easy_fx;

/////////////////////////////////////////////////////////////
custom_trap_init()
{
orbTag = "tag_origin";
orb = gent("radius_fx_origin");
orb_radius = gent("radius_fx_origin");
orb_trig = gent("custom_weapon_effects");
orb_trig sethintstring("Press &&1 to Summon Entity 115");
thread trap_trig(orb,orbTag,orb_radius,orb_trig);
flag_init("killing_time");
}
/////////////////////////////////////////////////////////////
gent(targetname)
{
tn = getent(targetname, "targetname");
return tn;
}
/////////////////////////////////////////////////////////////
trap_trig(orb,orbTag,orb_radius,orb_trig)
{
orb_trig waittill("trigger");
orb_trig trigger_off();
flag_set("killing_time");
thread master_orb_spawn(orb,orbTag,orb_radius,orb_trig);
thread master_orb_brain(orb);
}
/////////////////////////////////////////////////////////////
master_orb_spawn(orb,orbTag,orb_radius,orb_trig)
{
master_orb = Spawn("script_model",orb.origin );
master_orb SetModel( "tag_origin" );
master_orb.angles = orb.angles;
master_orb.origin = orb.origin;
master_orb LinkTo(master_orb, orbTag );
PlayFxOnTag( level._effect["trap_orb"], master_orb, orbTag );
wait 60;
master_orb delete();
orb_trig trigger_on();
flag_clear("killing_time");
thread trap_trig(orb,orbTag,orb_radius,orb_trig);
}
/////////////////////////////////////////////////////////////
master_orb_brain(orb)
{
while(flag("killing_time"))
{
iprintln("killing_time loop");
ai = getaiarray("axis");
excluders = undefined;
zombies = get_array_of_closest( orb.origin, ai, excluders, 500, 500 );
dogs = getaiarray("zombie_dog");
if(isdefined(dogs))
{
for(i=0;i<dogs.size;i++)
dogs[i] thread minions(orb);
}
if(isdefined(zombies))
{
for(i=0;i<zombies.size;i++)
{
zombies[i] thread minions(orb);
zombies[i] setGoalPos(orb.origin);
}
}
wait 1;
}
}
/////////////////////////////////////////////////////////////
minions(orb)
{
players = get_players();
x = 0;
iprintln("minion spawned");
minion = Spawn("script_model",orb.origin+( 0,0,100));
minion setmodel("tag_origin");
dist = distance2d(orb.origin,self.origin);
radius = 500;
time = undefined;
if(dist >= radius* 0.75)
{
time = 2;
}
else if(dist <= radius* 0.75 && dist >= radius* 0.45)
{
time = 1;
}
PlayFxOnTag(level._effect["trap_orb"],minion,"tag_origin");
while(isdefined(minion))
{
// orb moveto(player[0].origin);
x = x+1;
z = 50* sin(x);
splat = randomInt(30);
dist = distance2d(orb.origin,self.origin);
calibrate = 0;
minion moveto(self.origin+(0,0,z),(time - calibrate),0,0);
if(self isTouching(minion))
{
iprintln("minion touched zombie");
playfx(level._effect["minion_impact"],self.origin);
playfx(level._effect["squishy_rat"],self.origin+(0,0,splat));
self dodamage(10000);
minion delete();
break;
}
wait.05;
if(calibrate >=1 || dist <= 75)
{
minion setorigin(self.origin+(0,0,50));
playfx(level._effect["minion_impact"],self.origin);
playfx(level._effect["squishy_rat"],self.origin+(splat,0,0));
playfx(level._effect["squishy_rat"],self.origin+(0,splat,0));
playfx(level._effect["squishy_rat"],self.origin+(0,0,splat));
self dodamage(10000);
minion delete();
break;
}
else calibrate = calibrate + .05;
}
wait time;
minion delete();
}

This is a trap I made, named Entity 115. It has a master singularity that floats above a totem, and then it shoots energy wave projectiles (looks like ball lightning with glowing plasma) at enemies for 1 minute. Once you upgrade it, the singularity is supposed to follow the player above their shoulder within sight of the first person view. This is the only thing I can't get to work, I included all the code that I wrote for this section if it helps.

Double Post Merge: August 13, 2016, 05:01:44 am
Sorry I keep forgetting things, on the line where it says

zombies setGoalPos(orb.origin);

Disregard//comment that out if you test it, it was just something I was fooling around with last night trying to get the zombies to path towards the singularity, which I don't think I want to use anyways. But for some reason that line (I think) was spawning a second master orb above the script model that the "original" master orb spawns at, weird... but unrelated.

Double Post Merge: August 13, 2016, 05:43:31 am
Grrr >:(

I just realized how retarded my last edit was. I posted that script and forgot that I removed the getangles part of it so I could isolate it until I got the iprints working. So in that code, when the minions are spawned, they spawn on the master orb and path to the zombies. When the master brain part threads the zombies as self into the minion spawning logic, the minions are spawned at the master orb origin, so naturally if the orb is floating right wing to the player then the minions will follow suit, which is the intention. This is where I need to get the players angles so I can toss them into the while loop so that before the minion spawns each cycle, the master orb will get moved to the little devil spot so the minions get dispatched above the player.

Double Post Merge: August 13, 2016, 06:03:49 am
I noticed a few more errors  :-[

Here is the current working version of the script:
Code Snippet
Plaintext
#include common_scripts\utility; 
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\ugx_easy_fx;

/////////////////////////////////////////////////////////////
custom_trap_init()
{
players = get_players();
thread test_angles_and_print(players);
orbTag = "tag_origin";
orb = gent("radius_fx_origin");
orb_trig = gent("custom_weapon_effects");
orb_trig sethintstring("Press &&1 to Summon Entity 115");
thread trap_trig(orbTag,orb,orb_trig);
flag_init("killing_time");
}
/////////////////////////////////////////////////////////////
gent(targetname)
{
tn = getent(targetname, "targetname");
return tn;
}
/////////////////////////////////////////////////////////////
trap_trig(orbTag,orb,orb_trig)
{
orb_trig waittill("trigger");
orb_trig trigger_off();
flag_set("killing_time");
thread master_orb_spawn(orbTag,orb,orb_trig);
thread master_orb_brain(orb);
}
/////////////////////////////////////////////////////////////
master_orb_spawn(orbTag,orb,orb_trig)
{
master_orb = Spawn("script_model",orb.origin );
master_orb SetModel( "tag_origin" );
master_orb.angles = orb.angles;
master_orb.origin = orb.origin;
master_orb LinkTo(master_orb, orbTag );
PlayFxOnTag( level._effect["trap_orb"], master_orb, orbTag );
wait 60;
master_orb delete();
orb_trig trigger_on();
flag_clear("killing_time");
thread trap_trig(orb,orbTag,orb_radius,orb_trig);
}
/////////////////////////////////////////////////////////////
master_orb_brain(orb)
{
while(flag("killing_time"))
{
iprintln("killing_time loop");
ai = getaiarray("axis");
excluders = undefined;
zombies = get_array_of_closest( orb.origin, ai, excluders, 500, 500 );
dogs = getaiarray("zombie_dog");
if(isdefined(dogs))
{
for(i=0;i<dogs.size;i++)
dogs[i] thread minions(orb);
}
if(isdefined(zombies))
{
for(i=0;i<zombies.size;i++)
{
zombies[i] thread minions(orb);
// zombies[i] setGoalPos(orb.origin);
}
}
wait 1;
}
}
/////////////////////////////////////////////////////////////
minions(orb)
{
players = get_players();
thread test_angles_and_print(players);
x = 0;
iprintln("minion spawned");
minion = Spawn("script_model",orb.origin+( 0,0,100));
minion setmodel("tag_origin");
dist = distance2d(orb.origin,self.origin);
radius = 500;
time = undefined;
if(dist >= radius* 0.75)
{
time = 2;
}
else if(dist <= radius* 0.75 && dist >= radius* 0.45)
{
time = 1;
}
PlayFxOnTag(level._effect["trap_orb"],minion,"tag_origin");
while(isdefined(minion))
{
// orb moveto(player[0].origin);
x = x+1;
z = 50* sin(x);
splat = randomInt(30);
dist = distance2d(orb.origin,self.origin);
calibrate = 0;
minion moveto(self.origin+(0,0,z),(time - calibrate),0,0);
if(self isTouching(minion))
{
iprintln("minion touched zombie");
playfx(level._effect["minion_impact"],self.origin);
playfx(level._effect["squishy_rat"],self.origin+(0,0,splat));
self dodamage(10000);
minion delete();
break;
}
wait.05;
if(calibrate >=1 || dist <= 75)
{
minion setorigin(self.origin+(0,0,50));
playfx(level._effect["minion_impact"],self.origin);
playfx(level._effect["squishy_rat"],self.origin+(splat,0,0));
playfx(level._effect["squishy_rat"],self.origin+(0,splat,0));
playfx(level._effect["squishy_rat"],self.origin+(0,0,splat));
self dodamage(10000);
minion delete();
break;
}
else calibrate = calibrate + .05;
}
wait time;
minion delete();
}
//////////////////////////////////////////////////////////////
test_angles_and_print();
{
while(1)
{
pangles = players getPlayerAngles();
f = anglesToForward(pangles);
u = anglesToUp(pangles);
r = anglesToRight(pangles);
if(isdefined(pangles))
iprintln(pangles,f,u,r);
wait .5;
}
}

//////////////////////////////////////////////////////////////
The test_angles_and_print() function at the end I can't get working. I don't know if it's the syntax, I can't tell which part is failing, I'm getting no errors :(

Double Post Merge: August 13, 2016, 06:15:54 am
+5 more idiot points for me.
*Fixed and removed undefined variable "orb_radius" on line 46
Code Snippet
Plaintext
	thread trap_trig(orb,orbTag,orb_radius,orb_trig);  //<--orb_radius removed. - same as "orb" using script for radius anyways
Last Edit: August 13, 2016, 06:15:54 am by Archaicvirus
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Alright I finally got it working with this:

Code Snippet
Plaintext
guardian_follow(master_orb,player)
{
while(flag("killing_time"))
{
f = anglesToForward(player.angles)*50;
r = anglesToRight(player.angles)*30+f;
r = r+(0,0,60);
master_orb moveto(player.origin+(r),.1,0,0);
wait .1;
}
}

Thanks for pointing me in the right direction. This looks so awesome now! It floats in the top right of the player's view, perfect.
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
I'm uploading the video of it working now to yt, will post the link in a few minutes.
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Here's the link for the video of it working
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
Yea that's what I meant

Ugx script reference just has a typo, should be ( angle ) like you've done

Looks cool btw, good job
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Thanks man. I'm almost done making a variation of it where it doesn't shoot projectiles, but acts as an energy barrier circling the player. To be honest, it's going to be one of four easter egg style wonder weapons, like with the bows or staffs. Each one is going to have an elemental effect, like the singularity one, a wind style one that will have a small radial effect similar to the thunder gun, one will be fire tornado's circling the player and sending out smaller tornado drones, and the last one is going to be similar to the gersch device. It's a big undertaking but pretty persistent. I'm sure I'll be bugging more on the forums for help along the way haha.
broken avatar :(
×
broken avatar :(
Location: ph
Date Registered: 22 May 2016
Last active: 4 months ago
Posts
225
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
Signature
×
KhelMho's Groups
KhelMho's Contact & Social Links
Wow, nice scripting  :rainbow:
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Thanks. It took almost 20 hours. I'm really slow at coding, but I've been learning fast.

 
Loading ...