2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: joy force
[Re: Funeral]
#383849
09/26/11 09:58
09/26/11 09:58
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
Well thats because the joy_force.x/y values are not zero most of the time. This means you would have to use a threshold value before the actor reacts. So one method that comes to my mind right now (there are several others and I bet even better ones):
VECTOR forceVec; // our vector we will set depending on joy_force and use for rotation - global definition or local but not in a loop!
var forceThreshold = 0.1; // our threshold value, adjust this if needed
...
// in the function:
vec_set(forceVec, nullvector); // reset our forceVec
if(abs(joy_force.x) > forceThreshold)
{
forceVec.x = sign(joy_force.x);
}
if(abs(joy_force.y) > forceThreshold)
{
forceVec.y = sign(joy_force.y);
}
vec_to_angle(my.pan, forceVec);
my.pan -= 90;
Last edited by Xarthor; 09/26/11 10:01.
|
|
|
Re: joy force
[Re: Funeral]
#383903
09/27/11 01:02
09/27/11 01:02
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
joy_force probably isn't the cause of the problem it more than likely lies somewhere else in your code. simple test: create a level that only rotates a simple object and see if the problem continues
#include <acknex.h>
#include <default.c>
action the_player(){
while(me){
vec_to_angle(my.pan, vector(sign(joy_force.x),sign(joy_force.y),0));
wait(1);
}
}
void main(){
wait(1);
level_load(NULL);
ent_create(CUBE_MDL, vector(150, 0, 0), the_player);
}
if you still have the problem display joy_force.x and .y to determine if they're not resetting and what their values are
...
DEBUG_VAR(joy_force.x, 20);
DEBUG_VAR(joy_force.x, 20);
if these are showing there's still problems try it with a different joypad. if these aren't the problem post some more of your code as the problem is elsewhere
|
|
|
Re: joy force
[Re: MrGuest]
#383905
09/27/11 01:57
09/27/11 01:57
|
Joined: Dec 2008
Posts: 83 Buenos Aires, Argentina
Funeral
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
|
The problem probably is that you, Funeral, did not adjust the variable var forceThreshold = 0.1; as Xarthor suggested. Try a higher value. I think I use a similar approach with a threshold of "0.3". yes i did tried with higher and lower values.. joy_force probably isn't the cause of the problem it more than likely lies somewhere else in your code. simple test: create a level that only rotates a simple object and see if the problem continues
#include <acknex.h>
#include <default.c>
action the_player(){
while(me){
vec_to_angle(my.pan, vector(sign(joy_force.x),sign(joy_force.y),0));
wait(1);
}
}
void main(){
wait(1);
level_load(NULL);
ent_create(CUBE_MDL, vector(150, 0, 0), the_player);
}
if you still have the problem display joy_force.x and .y to determine if they're not resetting and what their values are
...
DEBUG_VAR(joy_force.x, 20);
DEBUG_VAR(joy_force.x, 20);
if these are showing there's still problems try it with a different joypad. if these aren't the problem post some more of your code as the problem is elsewhere hmm yes maybe, there's a camera code that also uses "vec_to_angle" maybe that is? this is the code: var distance, angle; VECTOR temp; distance = 200; while(1) { if(player) { camera.x = player.x-distance*cos(angle); camera.y = player.y-distance*sin(angle); camera.z = player.z+20; vec_set(temp,player.x); vec_sub(temp,camera.x); vec_to_angle(camera.pan,temp);
|
|
|
|