Two entity questions.
Moderator: InsideQC Admins
4 posts
• Page 1 of 1
Two entity questions.
Alright i have two questions about entities:
(1) Is there a way to set an entity's origin to a random vector? (I know about dp's randomvec, but is there a non-darkplaces way to do it?)
(2) Is there a way to move one entity towards another? IE: Entity 1 is placed at the start of a hallway, and entity 2 is at the end. Entity 1 moves toward entity 2.
Thanks.
-Duster
(1) Is there a way to set an entity's origin to a random vector? (I know about dp's randomvec, but is there a non-darkplaces way to do it?)
(2) Is there a way to move one entity towards another? IE: Entity 1 is placed at the start of a hallway, and entity 2 is at the end. Entity 1 moves toward entity 2.
Thanks.
-Duster
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
In a hurry to get to work atm.. so i'll just answer 2.
setorigin(entity1, entity2.origin);
setorigin(entity1, entity2.origin);
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
knowing a bit of vector maths will help you a lot with QC.
your second question can be solved with a few simple things:
1. find the direction vector towards the other entity
2. change position in that direction.
first:
local vector vec;
local entity e;
e = find the other entity you want to head towards in whatever way you want;
vec = e.origin - self.origin; //this gets the vector from self to e.
vec = normalize(vec); //normalize changes the vector to a vector with a length of 1 but without changing the direction.
vec = vec * <some arbitrary number>;
setorigin(self, self.origin + vec); //this adds the vector we made to the current position.
note: always use setorigin, never set .origin directly. doing so can screw up some things with the engine, such as visibility, lighting and something called 'entity links'.
as for random vector positions, that can be done like so:
local vector vec;
vec_x = random() * 8192 - 4096;
vec_y = random() * 8192 - 4096;
vec_z = random() * 8192 - 4096;
setorigin(self, vec);
this will set the position to a random location within -4096 and + 4096. if you're using DP or another engine that increases the max world extents, you may need to increase this number.
your second question can be solved with a few simple things:
1. find the direction vector towards the other entity
2. change position in that direction.
first:
local vector vec;
local entity e;
e = find the other entity you want to head towards in whatever way you want;
vec = e.origin - self.origin; //this gets the vector from self to e.
vec = normalize(vec); //normalize changes the vector to a vector with a length of 1 but without changing the direction.
vec = vec * <some arbitrary number>;
setorigin(self, self.origin + vec); //this adds the vector we made to the current position.
note: always use setorigin, never set .origin directly. doing so can screw up some things with the engine, such as visibility, lighting and something called 'entity links'.
as for random vector positions, that can be done like so:
local vector vec;
vec_x = random() * 8192 - 4096;
vec_y = random() * 8192 - 4096;
vec_z = random() * 8192 - 4096;
setorigin(self, vec);
this will set the position to a random location within -4096 and + 4096. if you're using DP or another engine that increases the max world extents, you may need to increase this number.
- necros
- Posts: 77
- Joined: Thu Dec 16, 2004 10:32 pm
Goes to show how much of a hurry I was in, didn't even read the question properly 
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest