joy force

Posted By: Funeral

joy force - 09/25/11 00:28

hi. i have this:

f(sign(joy_force.y) == 1)
my.pan = 0;

if(sign(joy_force.y) == -1)
my.pan = 180;


if(sign(joy_force.x) == 1)
my.pan = -90;

if(sign(joy_force.x) == -1)
my.pan = 90;

its change the pan position of and entity with the joystick. forward, left and right.. oº, 180º, 90º, and -90º.
but how can i get my entity to change 8 positions instead of 4? for insteance, to change its position to 45º ?
Posted By: Xarthor

Re: joy force - 09/25/11 08:00

This can be done much simpler using a vector and the built-in vec_to_angle function. Here come the two lines you need:
Code:
vec_to_angle(my.pan, vector(sign(joy_force.x),sign(joy_force.y),0));
my.pan -= 90; // needed because you want (0,1,0) to result in pan = 0


Posted By: Funeral

Re: joy force - 09/26/11 00:13

hi! thx for tip! laugh it works well and its what was looking for, except for one detail: the player just keeps spinning around non-stop when the joystick its not moving, so which part of the code needs to be fixed?
Posted By: Xarthor

Re: joy force - 09/26/11 09:58

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):
Code:
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;


Posted By: Funeral

Re: joy force - 09/27/11 00:31

nop, the problem persist frown
Posted By: MrGuest

Re: joy force - 09/27/11 01:02

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
Code:
#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
Code:
...
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
Posted By: Superku

Re: joy force - 09/27/11 01:08

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".
Posted By: Funeral

Re: joy force - 09/27/11 01:57

Originally Posted By: Superku
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..
Originally Posted By: MrGuest
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
Code:
#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
Code:
...
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);
Posted By: Funeral

Re: joy force - 09/28/11 01:09

the problem is solved!!!
the vec_to_angle(my.pan, vector(sign(joy_force.x),sign(joy_force.y),0));
my.pan -= 90; code was right, but for some reason i had to replace my.pan -= 90;
by my.pan -= 0;
Posted By: MrGuest

Re: joy force - 09/28/11 01:16

if you're using my.pan -= 0; you should remove it altogether, it's subtracting 0 from itself unaffecting its value
Posted By: Funeral

Re: joy force - 09/28/11 02:06

yep, its werid but it works! =P with "-90" the player kept spinning around non stop, and with "-0" it works. i also tried "0" but then it just didnt turn.
Posted By: Xarthor

Re: joy force - 09/29/11 14:17

Ah now I see my fault, sorry for this.
The -= 90 offset should only be executed if the angle was updated, this I did not consider.
I'd suggest this code:
Code:
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);
}

if(vec_length(joy_force) > 0) // any change?
{
    vec_to_angle(my.pan, forceVec);
    my.pan -= 90; // remove this line if no offset needed
}


Posted By: Funeral

Re: joy force - 09/30/11 00:18

thx! yes its solved now :), hmm but another problem came up, now: its a 3d person, and when i rotate the camera(pan angle) the player's doesnt adjust to the screen and it takes the x axis the right of the screen, so if i move the joystick forward the player turns and walk to the right.. should i ask here or make a new post?
Posted By: Xarthor

Re: camera dependent movement - 09/30/11 08:19

So you want the move directions of the character to be dependent on the angle of the camera?

When the player moves the character forward and while moving changes the camera angle, should the character automatically adapt to this change (means rotate too) or should he keep moving the direction he had before rotating the camera?
Posted By: Funeral

Re: camera dependent movement - 09/30/11 23:54

see, its for a 3rd person game like super mario, so when i move the joystick forward it moves forward, but when i rotate the camera's pan angle and i move the joystick forward the player keeps going to the same direction as before.
i mean the X axis has to change automaticly to adjust to the joystick movements.

for insteance if i rotate the camera 90º, the player goes to the right when i move the joystick forward.

hmm dunno if i was clear enough...
Posted By: Funeral

Re: camera dependent movement - 10/03/11 18:32

and that's pretty much the whole thing... and it doesnt work just by using relative speed in c_move
Posted By: Funeral

Re: camera dependent movement - 12/23/11 19:32

Originally Posted By: Xarthor
So you want the move directions of the character to be dependent on the angle of the camera?

When the player moves the character forward and while moving changes the camera angle, should the character automatically adapt to this change (means rotate too) or should he keep moving the direction he had before rotating the camera?


first option laugh
© 2024 lite-C Forums