Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
New to gamestudio got a quick question #292324
10/01/09 22:50
10/01/09 22:50
Joined: Oct 2009
Posts: 60
T
Tman Offline OP
Junior Member
Tman  Offline OP
Junior Member
T

Joined: Oct 2009
Posts: 60
Hello guys and girls I have a quick question I am tying to get this model not to float in the air when I press the forward key and use the mouse to pan up, how would I prevent this. Here is the code:

#define _MoveVec 14 /*14 to 16 ARE USED BE THIS SKILL*/

//This function gets the camera to follow the mouse movement and translate
//that into pan/tilt values, accordingly. It does NOT position the camera.
function FirstPersonCamera()
{
while(1)
{

camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 12 * time_step;

if(camera.tilt > 60)
{
camera.tilt = 60;
}
else
{
if(camera.tilt < -60)
{
camera.tilt= -60;
}
}

wait(1);
}
}

action PlayerMove()
{


//camera made for the player
FirstPersonCamera();

player = my;
//player position on the ground
my.z = - 150;

var ForwardBack = 0;
var LeftRight = 0;
var groundDist = 0;

VECTOR temp;
VECTOR movement;
var anim_percent;

vec_set(movement, vector(0,0,0));


while(!my) wait(1);

while(1)
{


//Forward and back movement
if (key_w == 1) {ForwardBack = 1;}
if (key_s == 1) {ForwardBack = -1;}

if (key_a == 1) {LeftRight = 1;}
if (key_d == 1) {LeftRight = -1;}

if (key_w == 0 && key_s == 0) //No key pressed, clear the mp_move skills
{
ForwardBack = 0;
}
if (key_a == 0 && key_d == 0) //No key pressed, clear the mp_move skills
{
LeftRight = 0;
}

//Now perform local movement prediction
my.skill[_MoveVec] = ForwardBack * 15* time_step;
my.skill[_MoveVec+1] = LeftRight * 7 * time_step;
vec_set(movement, my.skill[_MoveVec]);

//Now move the player
c_move(my,movement,nullvector,IGNORE_PASSABLE | GLIDE | USE_BOX | USE_POLYGON);
vec_set(temp, my.x);
vec_sub(temp, vector(0,0,1000));
groundDist = c_trace(my.x,temp,IGNORE_ME | IGNORE_PASSABLE | USE_BOX | USE_POLYGON);
if ((groundDist > 500 ))
{
my.skill[_MoveVec+2] = -2 * time_step; //Modify Z

}


//Rotation: Player has exact same rotation function as camera. Should use c_rotate! NOTE FOR UPDATE!
my.pan = camera.pan;
my.tilt = camera.tilt;

//Update the camera position
vec_set(camera.x, my.x);

VECTOR Dir;
vec_for_angle(Dir, my.pan);
vec_scale(Dir, -1.7);
vec_add(camera.x, Dir);

//Animate. Not efficient, but hey, good for now...
if ((ForwardBack != 0))
{
anim_percent += 1.3*ForwardBack; // 1.3 = walk cycle percentage per quant
ent_animate(me,"walk",anim_percent,ANM_CYCLE); // play the "walk" animation
}
else // player stands still
{
anim_percent += 1*time_step;
ent_animate(me,"idle",anim_percent,ANM_CYCLE); // play the "stand" animation
}
wait(1);
}
}

Any help is appreciated.



Last edited by Tman; 10/01/09 22:50.
Re: New to gamestudio got a quick question [Re: Tman] #292450
10/03/09 16:57
10/03/09 16:57
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Better use the "code" tag for scripts, otherwise they are hard to read here. When your model floats its position is probably set up wrong in MED, make sure that the origin is in the models center and not at its feet.


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