Raised This Month: $32 Target: $400
 8% 

Random Vectors


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-22-2017 , 23:56   Random Vectors
Reply With Quote #1

Alright so I've been stumped on this one for awhile, perhaps its because I don't understand geometry very well but I simply want these entities to spawn in random around where the client is looking at. But no matter how much I try they always spawn randomly but also clearly in line with one another at an angle. Any idea what I'm doing wrong here? Or any pointers?

Spoiler


Note: My first issue was all the random points drifting up and to the right of the clients aim and I realized that was because I was just adding to the same vector. So I made 3 of them hense the ArtillarySmoke 1 - 3.
Halt is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-23-2017 , 00:24   Re: Random Vectors
Reply With Quote #2

Bit confused what you're doing with your code. You teleport ArtillarySmoke2 to the position ArtillarySmokePos2 but then also teleport ArtillarySmoke3 to ArtillarySmokePos2. Same with ArtillarySmoke4 and ArtillarySmokePos3. Then you add to ArtillarySmokePos3 even though you're not using it (unless there was some code cut off).

You could try doing something like this:
PHP Code:
for (int i 02i++) {

    
ArtillarySmokePos2[i] += GetRandomFloat(-250.0250.0);
    
ArtillarySmokePos3[i] += GetRandomFloat(-250.0250.0);
    
ArtillarySmokePos4[i] += GetRandomFloat(-250.0250.0);

}

TeleportEntity(ArtillarySmoke2ArtillarySmokePos2NULL_VECTORNULL_VECTOR);
TeleportEntity(ArtillarySmoke3ArtillarySmokePos3NULL_VECTORNULL_VECTOR);
TeleportEntity(ArtillarySmoke4ArtillarySmokePos4NULL_VECTORNULL_VECTOR); 
I'd also recommend doing some debug prints to see what positions they all end up at and whats happening at every stage of the code.

Last edited by hmmmmm; 05-23-2017 at 00:35.
hmmmmm is offline
Bobakanoosh
Senior Member
Join Date: Sep 2015
Location: United States
Old 05-23-2017 , 01:44   Re: Random Vectors
Reply With Quote #3

As hmmmmm mentioned, you're never changing the 2nd (or third, w/e) index of ArtillarySmokePos. A vector is three points, Float vec[3], X, Y, Z. You're only changing X and Y (Z is vertical) which is why they may seem to be landing in one line.
Bobakanoosh is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 05-23-2017 , 01:47   Re: Random Vectors
Reply With Quote #4

Quote:
Originally Posted by Bobakanoosh View Post
As hmmmmm mentioned, you're never changing the 2nd (or third, w/e) index of ArtillarySmokePos. A vector is three points, Float vec[3], X, Y, Z. You're only changing X and Y (Z is vertical) which is why they may seem to be landing in one line.
Vertical being in the air correct? The point is for the smoke to be on the ground.
Halt is offline
Bobakanoosh
Senior Member
Join Date: Sep 2015
Location: United States
Old 05-23-2017 , 01:53   Re: Random Vectors
Reply With Quote #5

X and Y represents you moving around on a flat plane. Z represents you crouching or jumping. It's vertical like the height of a building. If you never change Z, then everything will spawn at the same height.
Bobakanoosh is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-23-2017 , 04:50   Re: Random Vectors
Reply With Quote #6

Z (3rd index) is the height, but in your code you set up ArtillarySmokePos2:

PHP Code:
ArtillarySmokePos2[0] += GetRandomFloat(125.0250.0); //Done
ArtillarySmokePos2[1] -= GetRandomFloat(125.0250.0); //Done
TeleportEntity(ArtillarySmoke2ArtillarySmokePos2NULL_VECTORNULL_VECTOR); 

After that you only change the X component of ArtillarySmokePos2:

PHP Code:
ArtillarySmokePos2[0] -= GetRandomFloat(250.0500.0); //Done 

And then you teleport ArtillarySmoke3 to ArtillarySmokePos2:

PHP Code:
TeleportEntity(ArtillarySmoke3ArtillarySmokePos2NULL_VECTORNULL_VECTOR); 
without changing the Y component of ArtillarySmokePos2, meaning that ArtillarySmoke2 and ArtillarySmoke3 have the same Y position. Again, the way you've done this is confusing and I would recommend just doing a loop like the example I showed above. If you're still having trouble provide more context to your issue or:
Quote:
I'd also recommend doing some debug prints to see what positions they all end up at and whats happening at every stage of the code.

Last edited by hmmmmm; 05-23-2017 at 04:50.
hmmmmm 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 18:58.


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