|
1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Dynamically create special entities?
[Re: MrCode]
#178992
02/03/08 16:58
02/03/08 16:58
|
Joined: Jan 2008
Posts: 49 Sweden
Kenchu
Newbie
|
Newbie
Joined: Jan 2008
Posts: 49
Sweden
|
Quote:
Alright. I believe the time has come to start assigning behavior to these "magnets". I was thinking of using a spherical c_scan to detect nearby entities, and if it detects one or more, it will attract to it (or repel it), and the same goes for the others (because they also have their own c_scan).
I know the attraction/repulsion thing is going to involve a bit of trigonometry, and I've got that part worked out (mostly), but how can I use c_scan to detect whether the magnet is POSITIVE or NEGATIVE, if I can at all?
Are the me and you pointers universal, or can they only be used with entities?
Im not sure if you can use c_scan for that. It wouldve worked, as you say, if you somehow could access the pole member, but I dont see how to do that in a fancy way. One solution could be to store the entity pointer of MAGNET (ENTITY* entity) in an array, and the actual MAGENT pointer in another one, and keep these two coherent.
Then you could in the event handler find the ENTITY in the first array, and use that index to get the pole from the second array.
kinda like:
for each entity in array check if current entity == me if so, then the use this index else continue until
then you could use array2[index] to get an MAGENT*, and just do array2[index].pole.
Though I dont think this is a good solution. It takes time to search the array for each entity all the time. 
Another solution could be to implement your own distance measuering function for MAGNETs instead. Then youd have to have an array with your magnets, and then go through it and calculate the distance to the others and take action from that. I think theres more work for that though.
These are the two solutions I can come to think of right now...
|
|
|
|
|
|