Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (OptimusPrime, AndrewAMD), 14,580 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
What Is Wrong In This Little Code? #239022
12/01/08 21:30
12/01/08 21:30
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Hey everybody. Right now, I was messing around with some code and models with a car and a simple cube, and I started learning about how to control it with C_Move, and then set the camera to it and such.

But then, after awhile, it was working great. And...It stopped working? It loads up fine, the camera and everything is fine, but when I press the keys to move it forward, or turn, or go backwards, it doesn't do anything?

This is the code:

Code:
 	///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
ENTITY* car;


function main()
{
	level_load ("homework18.wmb");
	wait (2);
	car = ent_create("car1.mdl", vector(0,0,10), NULL);
	while(1)
{
	camera.x = car.x;
	camera.y = car.y;
	camera.z =  car.z +17;
	camera.tilt = -5;
	wait(1);
}
}

action my_car()
{
	while (1)
	{	
		
		if (key_a)
		{
			car.pan += 3*time_step; // increase the pan angle of the car
			camera.pan += 3*time_step;
	}
		if (key_d)
		{
			car.pan -= 3*time_step; // decrease the pan angle of the car
			camera.pan -= 3*time_step;
	}
		if (key_w) // press and hold the "Space" key to move the car
		{
			c_move (car, vector(15*time_step, 0, 0), nullvector, GLIDE);
	}
	   if (key_s)
	   {
	c_move (car, vector(-15*time_step, 0, 0), nullvector, GLIDE);
      }
	
	}
}




Anyone know what is wrong?

Re: What Is Wrong In This Little Code? [Re: MrTwiggy101] #239023
12/01/08 21:47
12/01/08 21:47
Joined: Mar 2002
Posts: 1,774
Magdeburg
F
FlorianP Offline
Serious User
FlorianP  Offline
Serious User
F

Joined: Mar 2002
Posts: 1,774
Magdeburg
you need a wait(1) in the while-loop of you car function


I <3 LINQ
Re: What Is Wrong In This Little Code? [Re: MrTwiggy101] #239024
12/01/08 21:47
12/01/08 21:47
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
This would be better I think.

Code:

 	///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
//ENTITY* car;


function main()
{
	level_load ("homework18.wmb");
	wait (2);
	//car = ent_create("car1.mdl", vector(0,0,10), NULL);
        ent_create("car1.mdl", vector(0,0,10), my_car);
	while(1)
{
	//camera.x = car.x;
	//camera.y = car.y;
	//camera.z =  car.z +17;
	//camera.tilt = -5;
	wait(1);
}
}

action my_car()
{
	while (1)
	{	
		
		if (key_a)
		{
			my.pan += 3*time_step; // increase the pan angle of the car
			//camera.pan += 3*time_step;
                        camera.pan = my.pan; // does same thing as above but is faster
	}
		if (key_d)
		{
			my.pan -= 3*time_step; // decrease the pan angle of the car
			//camera.pan -= 3*time_step;
                        camera.pan = my.pan; // // does same thing as above but is faster
	}
		if (key_w) // press and hold the "Space" key to move the car
		{
			c_move (my, vector(15*time_step, 0, 0), nullvector, GLIDE);
	}
	   if (key_s)
	   {
	c_move (my, vector(-15*time_step, 0, 0), nullvector, GLIDE);
      }
	
        camera.x = my.x;
	camera.y = my.y;
	camera.z =  my.z +17;
	camera.tilt = -5;

        wait(1);
	}
}


Your 2 main problems however were, 1) you never called the my_car action when you created car with ent_create(), 2) You left wait(1); out of while loop in my_car action.


Professional A8.30
Spoils of War - East Coast Games
Re: What Is Wrong In This Little Code? [Re: Locoweed] #239028
12/01/08 23:02
12/01/08 23:02
Joined: Nov 2008
Posts: 25
M
MrTwiggy101 Offline OP
Newbie
MrTwiggy101  Offline OP
Newbie
M

Joined: Nov 2008
Posts: 25
Thanks! That worked! laugh

But I have one more question. I realized, whenever I use the JUST c_move, whenever I go up ramps, it just keeps floating, so I decided I want to use physics code to move and such with gravity, and I wrote a code, but it has the exact same effect as the last one. It starts up fine, but it won't move at all?

I would REALLY appreciate it if anyone could tell me whats wrong and how to fix it, thanks laugh

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
VECTOR car_speed;
ENTITY* car;


function main()
{
	level_load ("homework18.wmb");
	wait (2);
	car = ent_create("car1.mdl", vector(0,0,10), NULL);
	ph_setgravity (vector(0, 0, -386));
	phent_settype (car, PH_RIGID, PH_BOX);
	phent_setmass (car, 10, PH_BOX);
	phent_setfriction (car, 70);
	phent_setdamping (car, 40, 40);
	phent_setelasticity (car, 10, 20);
	
	wait (1);
	while(1)
 {
	car_speed.x = 25 * (key_cur - key_cul);
	car_speed.y = 25 * (key_cuu - key_cud);
	car_speed.z = 0;
	camera.x = car.x;
	camera.y = car.y;
	camera.z =  car.z +17;
	camera.tilt = -5;
	wait (1);
 }
}




EDIT:

Hey! I just noticed, the car WAS moving. But like, its wierd. Its not moving like, forward, backwards, etc.... Its like, flipping over, like a ball rolling or something. How can I make it move forward and turn and stuff like C_Move, but still have physics like gravity effecting it?

Last edited by MrTwiggy101; 12/01/08 23:23.
Re: What Is Wrong In This Little Code? [Re: MrTwiggy101] #239035
12/01/08 23:55
12/01/08 23:55
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Hey, I'm guessing but you just need to change the axis in Med

Re: What Is Wrong In This Little Code? [Re: MrTwiggy101] #239045
12/02/08 05:48
12/02/08 05:48
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Hi,

I wouldn't even try to get into real physics just yet, but here is some work around code:

Code:

 	///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
//ENTITY* car;

var world_gravity = -9.8;

function main()
{
	level_load ("homework18.wmb");
	wait (2);
	//car = ent_create("car1.mdl", vector(0,0,10), NULL);
        ent_create("car1.mdl", vector(0,0,10), my_car);
	while(1)
{
	//camera.x = car.x;
	//camera.y = car.y;
	//camera.z =  car.z +17;
	//camera.tilt = -5;
	wait(1);
}
}

action my_car()
{

    var speed;
	while (1)
	{	
		
	my.pan += (key_a - key_d) * 3 * time_step;
        speed = (key_w - key_s) * 15;
         
        c_move (my, vector(speed*time_step, 0, 0), vector(0,0,world_gravity*time_step), GLIDE);

        camera.pan = my.pan;
        camera.x = my.x;
	camera.y = my.y;
	camera.z =  my.z +17;
	camera.tilt = -5;

        wait(1);
	}
}


You might have to adjust world_gravity higher or lower depending on you level scale.

Loco


Professional A8.30
Spoils of War - East Coast Games
Re: What Is Wrong In This Little Code? [Re: Locoweed] #239046
12/02/08 06:09
12/02/08 06:09
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
And make sure the collision hull of the model is above ground level or it will jam in place.

IE test this by placing car well above ground at the start, so it will fall to
ground level. Then you can see if the hull is right.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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

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