1 registered members (tomaslolo),
1,542
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: C-script help
[Re: cartoon_baboon]
#254174
03/01/09 15:35
03/01/09 15:35
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
var status_CarryObject = 0;
action object_act
{
var attached;
var offset[3];
attached = 0;
while(me)
{
if(status_CarryObject)
{
if(attached == 0)
{
vec_diff(offset,player.x,my.x);
attached = 1;
}
vec_set(my.x,offset.x);
vec_add(my.x,player.x);
}
else { attached = 0; }
wait(1);
}
}
Attention: not tested, if it blows up your machine its your fault Something along that line should work though edit: add the else status so now you should also be able to re-pick up that object. edit #2: forgot to mention: To use this you need a function which sets that status_CarryObject var to one on key press. If you want several objects being carried individually you have to use c_scan plus scan_events, but because you were talking only about one object I went the easy way
Last edited by Xarthor; 03/01/09 15:39.
|
|
|
Re: C-script help
[Re: Xarthor]
#254199
03/01/09 17:47
03/01/09 17:47
|
Joined: Feb 2006
Posts: 616 Netherlands
cartoon_baboon
OP
User
|
OP
User
Joined: Feb 2006
Posts: 616
Netherlands
|
Hi, thanks a lot for the help, this is a good start but the code doesn't do exactly what it should firstly when the key is pushed the object doesn't stay in it's original position, instead it jumps to a position exactly on the opposite side of the player. Also, though the object follows the player around correctly it doesn't take it's pan into account. The idea is that the if the object is in front of me when the button is pushed that it remains in front of me when I walk around(and look around, which I didn't specify in my original post) Hopefully you could take another look at the code to see what needs to be adjusted. Thanks in advance!
|
|
|
Re: C-script help
[Re: cartoon_baboon]
#254218
03/01/09 19:24
03/01/09 19:24
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
Ok I wrote myself a small test app to find a working solution and finally I found on:
action object_act
{
var attached;
var offset_dist[3];
var offset_angle[3];
attached = 0;
while(!player) { wait(1); }
while(my)
{
if(status_CarryBox)
{
if(attached == 0)
{
offset_angle[0] = player.pan;
offset_angle[1] = 0;
offset_angle[2] = 0;
offset_dist.x = my.x - player.x;
offset_dist.y = my.y - player.y;
offset_dist.z = 0;
attached = 1;
}
my.pan = player.pan;
vec_set(my.x,offset_dist.x);
vec_diff(temp,player.pan,offset_angle);
vec_rotate(my.x,temp);
vec_add(my.x,player.x);
}
else
{
attached = 0;
}
wait(1);
}
}
This code only takes the pan angle into consideration and the .z position is not altered as well. I hope this is what you were looking for.
|
|
|
Re: C-script help
[Re: cartoon_baboon]
#255137
03/07/09 21:48
03/07/09 21:48
|
Joined: Feb 2006
Posts: 616 Netherlands
cartoon_baboon
OP
User
|
OP
User
Joined: Feb 2006
Posts: 616
Netherlands
|
Well here I am again, in need of some help once more I wanted to include a new feature and I hoped I'd be able to adjust the code Xarthor made myself to get it working but no such luck. Basically what I need is for the computer to calculate the relative distance and angle of the player to object 1 (see the beuatifully drawn example below). Then the block has to be placed relative to the player just as the player is relative to object 1. Example: The player is standing infront of object 1 than the block will be infront of the player. If the player than turns around but doesn't move the block will remain in the center of the player's view. Really hope someone (Xarthor? ) can help with this. Thanks! cartoon_baboon
|
|
|
Re: C-script help
[Re: Xarthor]
#255162
03/08/09 10:24
03/08/09 10:24
|
Joined: Feb 2006
Posts: 616 Netherlands
cartoon_baboon
OP
User
|
OP
User
Joined: Feb 2006
Posts: 616
Netherlands
|
Hi, thanks for the reply. You want to place that block accordingly to the angle from the player to that object1 which is not the block? yes, that's correct. And it changes only its position if the player moves but not if he just turns? This isn't quite correct. When the player moves it's relative distance and angle to object one changes so yes, then the block has to change it's posistion as well. But when the player turns the block has to move as well to keep itself at the right angle to the player (for example, the block was in front of the player, then if the player was to turn the block has to kepe itself infront of the player) Thanks for taking the time to help with this. cartoon_baboon
|
|
|
Re: C-script help
[Re: cartoon_baboon]
#255253
03/09/09 08:15
03/09/09 08:15
|
Joined: Feb 2006
Posts: 616 Netherlands
cartoon_baboon
OP
User
|
OP
User
Joined: Feb 2006
Posts: 616
Netherlands
|
Well I managed to edit the code to get it to place the cube at the right position (see below). Problem is it only calculates everything once. So when I move and turn the player the cube stays at it's original position. I've tried to get it to update constantly, though it then manages to follow the player around it doesn't recalculate the offset and angle between the player and "objent". How should I edit it this code to get it do do that? var attached;
var offset_dist[3];
var offset_angle[3];
var attached = 0;
while(!player) { wait(1); }
if(status_CarryBox)
{
if(attached == 0)
{
offset_angle[0] = objent.pan;
offset_angle[1] = 0;
offset_angle[2] = 0;
offset_dist.x = (player.x-objent.x);
offset_dist.y = (player.y-objent.y);
offset_dist.z = 0;
attached = 1;
}
my.pan = player.pan;
vec_set(my.x,offset_dist.x);
vec_diff(temp,player.pan,offset_angle);
vec_rotate(my.x,temp);
vec_add(my.x,player.x);
} Thanks! cartoon_baboon
Last edited by cartoon_baboon; 03/09/09 08:19.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|