bounce back from enemy --need help

Posted By: hungryhobo

bounce back from enemy --need help - 02/01/10 00:20

hello, I have a script that hurts the player when they are hit by an entity, but i want the player to bounce back in the opposite direction of the entity hitting it.

how can i calculate the force vector to bounce back from being hit? I am using the physics engine.

this is what i have so far:

function bounce_back()
{
//point player towards object
vec_set(temp.x, you.x);
vec_sub(my.x, temp.x);
vec_to_angle(my.pan, temp.x);

var back_force;

vec_set(back_force.x, my.pan);
//take the pan and make it negative, multiply
vec_normalize(back_force, -10000000);

phent_addcentralforce(me, back_force.x);
}

tips would be appreciated. thank you
Posted By: testDummy

Re: bounce back from enemy --need help - 02/01/10 07:30


Code:
// C-Script?
ENTITY* eSrc;
ENTITY* eTarget;
//var temp[3];
function bounce_back(_eSrc, _eTarget, _nForce) {
	eSrc = _eSrc;
	eTarget = _eTarget;
	vec_diff(temp, eSrc.x, eTarget.x);	// temp points at eSrc?
	vec_normalize(temp, _nForce);
	
	phent_addcentralforce(eSrc, temp); //???
}

//...
bounce_back(me, you, 15); // ??


Posted By: hungryhobo

Re: bounce back from enemy --need help - 02/01/10 23:02

thanks for helping me! works like a charm and now i know how to add parameters for functions in c-script.

i really appreciate it.
© 2024 lite-C Forums