Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 863 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
joy force #383752
09/25/11 00:28
09/25/11 00:28
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
F
Funeral Offline OP
Junior Member
Funeral  Offline OP
Junior Member
F

Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
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º ?

Re: joy force [Re: Funeral] #383766
09/25/11 08:00
09/25/11 08:00
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
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



Re: joy force [Re: Xarthor] #383836
09/26/11 00:13
09/26/11 00:13
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
F
Funeral Offline OP
Junior Member
Funeral  Offline OP
Junior Member
F

Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
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?

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 Offline
Expert
Xarthor  Offline
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):
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;



Last edited by Xarthor; 09/26/11 10:01.
Re: joy force [Re: Xarthor] #383902
09/27/11 00:31
09/27/11 00:31
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
F
Funeral Offline OP
Junior Member
Funeral  Offline OP
Junior Member
F

Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
nop, the problem persist frown

Re: joy force [Re: Funeral] #383903
09/27/11 01:02
09/27/11 01:02
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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
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

Re: joy force [Re: MrGuest] #383904
09/27/11 01:08
09/27/11 01:08
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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".


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: joy force [Re: MrGuest] #383905
09/27/11 01:57
09/27/11 01:57
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
F
Funeral Offline OP
Junior Member
Funeral  Offline OP
Junior Member
F

Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
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);

Re: joy force [Re: Funeral] #384001
09/28/11 01:09
09/28/11 01:09
Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
F
Funeral Offline OP
Junior Member
Funeral  Offline OP
Junior Member
F

Joined: Dec 2008
Posts: 83
Buenos Aires, Argentina
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;

Re: joy force [Re: Funeral] #384002
09/28/11 01:16
09/28/11 01:16
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
if you're using my.pan -= 0; you should remove it altogether, it's subtracting 0 from itself unaffecting its value

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1