0 registered members (),
1,498
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: "remember" a variable
[Re: DJBMASTER]
#301159
12/08/09 16:44
12/08/09 16:44
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
OK, I am trying to create a catapult movement without physics. I have one object which rotates freely. the second object is inside the first object and has the same angle. vec_set(object2,object1); vec_set (object2.pan, object1.pan);. Then when the first object has the angle say vector(0,10,20). And if I press a button, the second object should catapult from the first one and I want to use this angle (vector(0,10,20)) to calculate its movement. However, I also need to ignore now vec_set(object2.pan,object1.pan), because I need only that angle, which I "memorized" (vector(0,10,20( to find the trajectory of movement, no matter how the object1 is rotated now. So my question is how to memorize an angle at the instant when the button was pressed to use it further? Another example: a ball is constantly rotating by 1 degree: 0+1=1, 1+1=2, 2+1 =3. For example I want to "memorize"this angle 3, so that I can make a variable velocity = 3; and then use c_move(me, vector(velocity,0,0),nullvector, GLIDE);. And I cannot just set velocity = ball.pan, because the ball continues to rotate 3+1=4, 4+1=5, which would constantly change the velocity value. Sorry, if I am bad in explanations
a generator of dull questions
|
|
|
Re: "remember" a variable
[Re: Joey]
#301160
12/08/09 16:54
12/08/09 16:54
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
So, you want to have an object spin in place, but you want to keep track of the pan value it had on startup? The easiest way to do this is to store the entity's original pan value in a skill so you can use it in other functions and stuff, like this:
ENTITY* spinning_ent;
action spinning_action()
{
spinning_ent = my; // I am the spinning entity
my.skill1 = my.pan; // store my original pan in SKILL1
while(my) // while I exist
{
my.pan += time; // increase my pan value
wait(1);
}
}
action comparing_action()
{
while(my) // while I exist
{
if( spinning_ent != null ) // validity check
{
my.pan = spinning_ent.skill1; // always set me to look in the direction you were originally set to
}
wait(1);
}
}
Note that I only use an entity pointer for the spinning object to make the comparisons between the two actions valid in this example. If you are finding the pointer referencing the spinning object some other way, you don't need to use an entity pointer like "spinning_ent".
|
|
|
Re: "remember" a variable
[Re: BastovBros]
#301363
12/09/09 22:27
12/09/09 22:27
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
If you take a look at the function 'c_move' you will see it has 2 vector parameters - 'reldist' and 'absdist'.
'reldist' is used to move using entity coordinates (local), and so the local axis change depending upon the entity rotation.
'absdist' is used to move using world coordiantes (global). No matter how your entity is rotated, it will move in the absolute world axis.
Going through the lite-c workshop will help you to solve these problems.
Last edited by DJBMASTER; 12/09/09 22:32.
|
|
|
|