Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (flink, AndrewAMD, TipmyPip, 1 invisible), 667 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Speed limit #222001
08/17/08 14:01
08/17/08 14:01
Joined: Mar 2008
Posts: 104
theDust Offline OP
Member
theDust  Offline OP
Member

Joined: Mar 2008
Posts: 104
Hi, i have 2 variables: player_speed.x and player_speed.y
How can i limit these variables ? They should not going over a specific value .For example 100 (and -100 for the negativ movement). Any ideas ?

Re: Speed limit [Re: theDust] #222007
08/17/08 14:30
08/17/08 14:30
Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
cro_games Offline
User
cro_games  Offline
User

Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
Try this:
player_speed.x = minv(100,(maxv(player_speed.x, -100))) // player_speed.x will be limited between -100 and 100

player_speed.y = minv(100,(maxv(player_speed.y, -100))) // player_speed.y will be limited between -100 and 100



Last edited by cro_games; 08/17/08 14:38.

Hello everyone my name is Ivan Mandic from "Frozen pixel studio". wink
-----------------------------------
Homepage: www.fpx-studio.com
e-mail: emu_hunter_1990@hotmail.com
(working on a game engine)
Re: Speed limit [Re: cro_games] #222012
08/17/08 15:13
08/17/08 15:13
Joined: Aug 2003
Posts: 7,439
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,439
Red Dwarf
player_speed.x = clamp(player_speed.x, -100, 100);
player_speed.y = clamp(player_speed.y, -100, 100);


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: Speed limit [Re: Michael_Schwarz] #222042
08/17/08 18:37
08/17/08 18:37
Joined: Mar 2008
Posts: 104
theDust Offline OP
Member
theDust  Offline OP
Member

Joined: Mar 2008
Posts: 104
This two codes are working but my player is moving a bit in the wrong direction now. Really weird...I'll try to fix this, any idea is welcome smile

btw I move my player ( a ball) with this code:
phent_addtorqueglobal (ball, player_speed);

Re: Speed limit [Re: theDust] #222052
08/17/08 19:21
08/17/08 19:21
Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
cro_games Offline
User
cro_games  Offline
User

Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
Than use this:
Code:
player_speed = minv(100,(maxv(player_speed, -100))) // player_speed will be limited between -100 and 100

or
Code:
player_speed = clamp(player_speed, -100, 100);


Last edited by cro_games; 08/17/08 19:22.

Hello everyone my name is Ivan Mandic from "Frozen pixel studio". wink
-----------------------------------
Homepage: www.fpx-studio.com
e-mail: emu_hunter_1990@hotmail.com
(working on a game engine)
Re: Speed limit [Re: cro_games] #222056
08/17/08 19:59
08/17/08 19:59
Joined: Mar 2008
Posts: 104
theDust Offline OP
Member
theDust  Offline OP
Member

Joined: Mar 2008
Posts: 104
Hmmm, it says error:

"Can not convert `struct VECTOR` to `Fixed`
player_speed = clamp(player_speed, -100, 100);

"Can not convert `Fixed` to `struct VECTOR`
player_speed = clamp(player_speed, -100, 100);


My, player_speed is a vector, maybe this is the problem ?

Re: Speed limit [Re: theDust] #222060
08/17/08 20:31
08/17/08 20:31
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
post your code, it's easier to highlight the problem smile

Re: Speed limit [Re: MrGuest] #222070
08/17/08 21:06
08/17/08 21:06
Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
cro_games Offline
User
cro_games  Offline
User

Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
You use physics,add this to the code:

phent_setdamping(ball_entity,70,70);


Hello everyone my name is Ivan Mandic from "Frozen pixel studio". wink
-----------------------------------
Homepage: www.fpx-studio.com
e-mail: emu_hunter_1990@hotmail.com
(working on a game engine)
Re: Speed limit [Re: cro_games] #222168
08/18/08 10:19
08/18/08 10:19
Joined: Mar 2008
Posts: 104
theDust Offline OP
Member
theDust  Offline OP
Member

Joined: Mar 2008
Posts: 104
Here the action of my player:

action spieler()
{
zeiger = my;
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY);
phent_settype (zeiger, PH_RIGID, PH_SPHERE);
phent_setmass (zeiger, 1,PH_SPHERE);
phent_setfriction (zeiger, 500);
phent_setdamping (zeiger, 10, 50);
phent_setelasticity (zeiger, 50, 100);


while (1)
{
jump.x = 0; jump.y = 0; jump.z = 30000;
my.event = jump2;
winkel = cam_angle + 270;
if(key_cur)
cam_angle -= 3*time_step;
if(key_cul)
cam_angle += 3*time_step;

if(key_cuu)
{
player_speed.x -= cos (winkel) * 3 *time_step;
player_speed.y -= sin (winkel) * 3 *time_step;
}

if(key_cud)
{
player_speed.x += cos (winkel) * 3 *time_step;
player_speed.y += sin (winkel) * 3 *time_step;
}

if(key_cud != 1 && key_cuu != 1)
{
player_speed.x = 0;
player_speed.y = 0;
}
cam();
phent_addtorqueglobal (zeiger, player_speed);
wait (1);
}
}


player_speed is a vector (i have written VECTOR player_speed; in my Code). As you can see i always have used phent_setdamping, that doesn't help.

Last edited by theDust; 08/18/08 10:21.
Re: Speed limit [Re: theDust] #222266
08/18/08 17:52
08/18/08 17:52
Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
cro_games Offline
User
cro_games  Offline
User

Joined: Sep 2007
Posts: 761
Hrvatska (Croatia ), Slavonski...
if(key_cuu)&&(player_speed.x > -100)
{
player_speed.x -= cos (winkel) * 3 *time_step;
player_speed.y -= sin (winkel) * 3 *time_step;
}

if(key_cud)&&(player_speed.x < 100)
{
player_speed.x += cos (winkel) * 3 *time_step;
player_speed.y += sin (winkel) * 3 *time_step;
}


Hello everyone my name is Ivan Mandic from "Frozen pixel studio". wink
-----------------------------------
Homepage: www.fpx-studio.com
e-mail: emu_hunter_1990@hotmail.com
(working on a game engine)
Page 1 of 2 1 2

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