Moving an object

Posted By: pewpew

Moving an object - 01/01/09 08:02

if you have a tank, and you want to move it, is this the proper proceedure? -

1) apply physics to tank
2) move tank using c_move and c_rotate

i cant seem to get it working properly.

EDIT: heres the code i am trying to use - but it just jilts the tank left/right/up/down, then it returns to the original coordinates.

Code:
action move_tank()
{

	while(1)
	{
		//forward and reverse
		if(key_pressed(17) == 1)
			c_move(me, vector(10,0,0), nullvector, IGNORE_PASSABLE);
		if(key_pressed(31) == 1)
			c_move(me, vector(-10,0,0), nullvector, IGNORE_PASSABLE);
			
		//rotation
		if(key_pressed(30) == 1)
			c_rotate (me, vector(2,0,0), IGNORE_PASSABLE);
		if(key_pressed(32) == 1)
			c_rotate (me, vector(-2,0,0), IGNORE_PASSABLE);
		   
		//downwards
		if(key_pressed(46) == 1)
			c_move(me, vector(0, 0, -20 * time_step), nullvector, IGNORE_PASSABLE);
		wait(1);
	}
}


for some reason, only rotation works. and it only does so if i hold down key 46 (which presses the tank against the level)
Posted By: Petra

Re: Moving an object - 01/01/09 09:39

c_move only works then the object is not stuck in the floor or a wall. Why dont you learn about moving in the tutorial, look here:

http://www.conitec.net/litec/work18.htm
Posted By: pewpew

Re: Moving an object - 01/01/09 23:26

yeah it was actually workshop 18 and 19 i was using to teach myself. i still cant seem to get it to work?

so you say DONT use c_move if u are using physics??
Posted By: heinekenbottle

Re: Moving an object - 01/02/09 01:31

You might have better luck with this:

Code:
action move_tank()
{
  VECTOR speed;
  ANGLE rotAng;
  while(1)
  {
     rotAng.pan = 2 * (key_a - key_s) * time_step;
     c_rotate(my,rotAng,IGNORE_PASSABLE);
     speed.x = 10 * (key_w - key_s) * time_step;
     c_move(my,speed,nullvector,IGNORE_PASSABLE | GLIDE);
     wait(1);
  }
}

Posted By: pewpew

Re: Moving an object - 01/02/09 05:01

nope.. still doesnt work. ive been stuck on this for literally 2 months. its so annoying and frustrating frown

and i mean, its such a simple concept but i cant seem to find the correct solution!!!!

should i upload the project?
Posted By: Cowabanga

Re: Moving an object - 01/02/09 06:16

Hmmmm, So what's your version?
Posted By: pewpew

Re: Moving an object - 01/02/09 07:23

just the free version. i'm guessing there could be a conflict with commands that are restricted to the paid versions??
Posted By: Cowabanga

Re: Moving an object - 01/02/09 07:41

Not the edition, i mean the version. BTW, you can use c_move in the free version. wink
Posted By: Michael_Schwarz

Re: Moving an object - 01/02/09 14:23

http://3dgsnerd.xware-cg.com/code-snippet-1/
Posted By: DiegoFloor

Re: Moving an object - 01/02/09 22:16

I'm just beginning to learn too, so I may be wrong. But I think that when you're using physics you need to work with forces to move things around. I don't know how's your model, but depending on it you could apply a torque in the wheels or a simple force, pointing forward, in the gravity center of the whole object.

[edit: actually, I don't think it matters if the force is in the gc]
[edit2: actually, I don't think you can choose where to apply the force on an object! grin ]
Posted By: pewpew

Re: Moving an object - 01/04/09 00:51

thanks schwarz, i'll read over it laugh
Posted By: Davidus

Re: Moving an object - 01/04/09 01:12

Hi,
You're lucky, i have written an entity move script for myself,
so this may help you:

(Use the WSAD-Keys)
Code:
	VECTOR* vec = vector(0,0,0);
	
	if (key_pressed(17)) // forward
	{
		vec_for_angle(vec,vector(player.pan,0,0));
 		c_move(player,nullvector,vec,IGNORE_CONTENT | GLIDE);
   }
  	if (key_pressed(31)) // back
	{
		vec_for_angle(vec,vector((player.pan + 180)%360,0,0));
 		c_move(player,nullvector,vec,IGNORE_CONTENT | GLIDE);
   }
	if (key_pressed(30)) // rotate Left
	{
		c_rotate(player,vector(0.1,0,0),USE_AXISR);
   }
	if (key_pressed(32)) // rotate Right
	{
		c_rotate(player,vector(-0.1,0,0),USE_AXISR);
  	}	



Important:
You are confusing two concepts:
1. Inbuild Physics
2. (I call it) 'Manual Physics'.

1.) Physics System
If ypu are using the inbuilt physics system, then you give
your object 'out of control' and into the charge of the physics engine - this means that you should no more move your object by yourself.
You normally build wheels to your tank model,
and then build in a motor to turn this wheels.
Or you may simply push your object around -
if it was a ball (check out the ball example in your sample directory of your lite-c installation)
But if you would push your tank around like this, it would only look stupid - believe me, I tried it this way laugh )
A good example for building in wheels and moving the object with that is the bulldozer example
Link:Bulldozer Example on the Aknex ressource side

2.) 'manual physics'
There you move objects yourself - collision detection is
controlled by the flags you provide to the c_move function,
and depending on if an entity has a passable flag.
I personally recommend using the GLIDING flag,
because if you use a non-flat terrain, then your
tank won't get stuck that fast.

Pro for 2: Much faster, easiert to begin with
Downside: Not that nice, and you have to care for general physics by yourself (gravity for example is applied by manually c-moving your objects downside every frame)

I hope that helped a bit,
Davidus
Posted By: pewpew

Re: Moving an object - 01/04/09 10:53

Ohhhh............
david..
i see.
you hit the nail on the head.


i was trying to apply physics to full tank model (only the base was separated from the turret, not the wheels). Then i was trying to use c_move to push the tank around. and it was failing miserably.

I see exactly what you did with c_move, and also understand how i can use absolute and relative speed together to simulate the movement of the tank.

Thanks again laugh
© 2023 lite-C Forums