get the velocity of c_move

Posted By: Frederick_Lim

get the velocity of c_move - 01/13/08 12:41

I want to attach a particle tail to the entity, how to calculate the velocity of entity movement?
Posted By: Impaler

Re: get the velocity of c_move - 01/14/08 03:28

according to the manual, the syntax for c_move is:

Quote:



c_move(ENTITY* entity,VECTOR* reldist,VECTOR* absdist,var mode)






and since you have to specify the amount of distance it moves over, it should be easy to find the velocity, it's already in the reldist or absdist part of the above code.
Posted By: ultranet

Re: get the velocity of c_move - 01/14/08 04:24

Yes, the velocity vector is specified by the user.
Posted By: Frederick_Lim

Re: get the velocity of c_move - 01/17/08 11:09

I am trying to use this code to get the velocity, the velocity is use by effect() function. I get the velocity by calculate the position before and after c_move():
Code:
		bullet_speed.x = 80 * time_step; // adjust the speed of the bullet here

vec_set(pos1.x, my.x);
c_move(me, bullet_speed, nullvector, IGNORE_YOU|IGNORE_PASSABLE|IGNORE_FLAG2|ACTIVATE_SHOOT);
vec_set(pos2.x, my.x);
vec_sub(pos2.x, pos1.x);
vec_inverse(pos2);
effect(tail,1,my.x,pos2);


I enable beam for the effect(), but the result is very strange, is there anyone can help?
Posted By: Trooper119

Re: get the velocity of c_move - 01/17/08 21:15

Frederick, you should know by now that you should post your problem in one place, and document it to the fullest there. If possible give pictures (or if you really good a link to a short video). What people have been saying earlier is true, your value bullet_speed.x is your speed. c_move only moves as far as you let it, or until it runs into something that you deem not passable, but the fact remain that unless it hasn't moved that distance, bullet_speed.x is always the speed given. So unless your result looks strange once you hit an object, your code is rudunant, and you can pass bullet_speed.x if you'd like.

What it looks like your doing now is getting the real distance between the first and second point (before and after c_move) but I believe vec_inverse just gives the opposite of what you give it (+ to -, vise versa). I would suggest trying abs(value); to get the distance (absolute values turn everything to its + value), otherwise you may come up with negative distances, I'm guessing either this, or time_step is your problem, but I can't be 100% certain without pics.

I personally have unresolved issues with time_step, so I'm not a perfect person to ask, but as a few last ditch efforts I would suggest trying to pass just bullet_speed.x into your function and see what happens as a result. Also, you could try passing the event function before the c_move, I doubt it will do anything significant but you never know. Hope one of these solutions work, post back if you have any more problems, and if you find out time_step is giving you issues, please PM me or post back here, I would be interested in your findings.
Posted By: Frederick_Lim

Re: get the velocity of c_move - 01/18/08 13:52

Many thanks for reply. I mess up the particle's velocity and c_move function. There are relative and absolute movement vector in c_move, in my code I pass the relative vector in c_move, but is that the velocity vector for particle?

Most particle tutorials are using pre-calculate velocity, however I cannot figure out how to attach particle to moving entity.

Edit:
I solved my problem. I just need to divide the length of vector pos2.x, pos2.y, pos2.z by time_step, that's the velocity of c_move relative movement.
© 2024 lite-C Forums