1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
What Is Wrong In This Little Code?
#239022
12/01/08 21:30
12/01/08 21:30
|
Joined: Nov 2008
Posts: 25
MrTwiggy101
OP
Newbie
|
OP
Newbie
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: ///////////////////////////////
#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
FlorianP
Serious User
|
Serious User
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
Locoweed
Expert
|
Expert
Joined: Oct 2002
Posts: 2,256
Oz
|
This would be better I think.
///////////////////////////////
#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
MrTwiggy101
OP
Newbie
|
OP
Newbie
Joined: Nov 2008
Posts: 25
|
Thanks! That worked! 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  ///////////////////////////////
#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]
#239045
12/02/08 05:48
12/02/08 05:48
|
Joined: Oct 2002
Posts: 2,256 Oz
Locoweed
Expert
|
Expert
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:
///////////////////////////////
#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
Expert
|
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
|
|
|
|