Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 712 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Flying entities #475296
12/01/18 07:29
12/01/18 07:29
Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Pacific Offline OP
Guest
Pacific  Offline OP
Guest

Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Can someone help me with the code to control helicopter with physics engine?
please...

Last edited by Pacific; 12/01/18 07:30.

pac++
Re: Flying entities [Re: Pacific] #475317
12/01/18 18:53
12/01/18 18:53
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
you can set the movement speed of a physX actor by 'pXent_setvelocity'. If you set the speed each frame you are actually making it work like 'c_move' in global coordinates but inside the physX engine. 'pXent_setangvelocity' lets you control the actors rotation speed.

Set a vector as movement speed and accelerate it by key input.
W/S:front/back
A/D:left/right
cursorUp/cursorDown:up/down
Code:
my.skMoveX = clamp(my.skMoveX + (key_w - key_s) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;
my.skMoveY = clamp(my.skMoveY + (key_a - key_d) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;
my.skMoveZ = clamp(my.skMoveZ + (key_cuu - key_cud) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;



Then compute tilt and roll speed in reference to the movement and pan with an accelerated skill.
cursorLeft/cursorRight:rotateCCW/rotateCW
Code:
my.skRotX = my.skMoveY * ROLL_FACTOR - ang(my.roll) * RESTORE_FACTOR;
my.skRotY = my.skMoveX * TILT_FACTOR + ang(my.tilt) * RESTORE_FACTOR;
my.skRotZ = clamp(my.skRotZ + (key_cul - key_cur) * ACCELERATION, -MAX_ROT_SPEED, MAX_ROT_SPEED) * RESISTANCE;



Disclaimer: I never deeply tested this workaround, but it seams to work

Click to reveal..

Code:
#include <acknex.h>
#include <ackphysx.h>

#define PRAGMA_PATH "%EXE_DIR%templatesimages"
#define PRAGMA_PATH "%EXE_DIR%templatesmodels"

#define GRAVITY      100

BMAP *bmpTerrain = "rock.tga";

#define skMoveX         skill1
#define skMoveY         skill2
#define skMoveZ         skill3
#define skRotatX        skill4
#define skRotatY        skill5
#define skRotatZ        skill6

action actHc() {
	my->pan = 25;
	my->flags |= SHADOW;
	vec_fill(my->skMoveX, 0);
	vec_fill(my->skRotatX, 0);
	pXent_settype(me, PH_RIGID, PH_BOX);
	
	while(!key_esc) {
		var _accel = 100 * time_step;
		var _factor = 1 - time_step * 0.2;
		my->skMoveX = clamp(my->skMoveX + (key_w - key_s) * _accel, -400, 800) * _factor;
		my->skMoveY = clamp(my->skMoveY + (key_a - key_d) * _accel, -500, 500) * _factor;
		my->skMoveZ = clamp(my->skMoveZ + (key_cuu - key_cud) * _accel, -200, 200) * _factor;
		VECTOR _vMove;
		vec_set(&_vMove, &my->skMoveX);
		vec_rotate(&_vMove, vector(my->pan, 0, 0));
		pXent_setvelocity(me, &_vMove);
		
		VECTOR _vRot;
		_vRot.x = -ang(my->roll) * 10 - my->skMoveY * 0.6;
		_vRot.y = ang(my->tilt) * 10 + my->skMoveX * 0.2;
		my->skRotatZ = clamp(my->skRotatZ + (key_cul - key_cur) * 4, -80, 80) * _factor;
		_vRot.z = my->skMoveY * 0.01 * my->skMoveX * 0.01 + my->skRotatZ;
		vec_rotate(&_vRot, vector(my->pan, 0, 0));
		pXent_setangvelocity(me, &_vRot);
		
		camera->x = -300;
		camera->y = 0;
		camera->z = 130;
		vec_rotate(&camera->x, vector(my->pan, 0, 0));
		vec_add(&camera->x, &my->x);
		camera->pan = my->pan;
		
		wait(1);
	}
	
	sys_exit(NULL);
}

action actCube() {
	my->pan = random(360);
	vec_fill(my->scale_x, 4);
	my->flags |= SHADOW;
	pXent_settype(me, PH_RIGID, PH_BOX);
}

void main() {
	video_mode = 10;
	fps_max = 60;
	wait(3);
	on_0 = NULL;
	physX_open();
	pX_setunit(0.25);
	pX_setgravity(vector(0, 0, -GRAVITY));
	
	level_load("");
	camera->tilt = -10;
	
	ENTITY *_entTerrain = ent_createterrain(bmpTerrain, nullvector, 1, 1, 16384);
	pXent_settype(NULL, PH_STATIC, PH_PLANE); // create a static plane at groundlevel zero
	
	int _i = 0;
	for(; _i<100; _i+=1)
		ent_create("dumper1.MDL", vector(random(16000)-8000,random(16000)-8000,100), actCube);
	ent_create("buggy.MDL", vector(0,0,400), actHc);
}



Enjoy!

Re: Flying entities [Re: txesmi] #475509
12/17/18 17:57
12/17/18 17:57
Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Pacific Offline OP
Guest
Pacific  Offline OP
Guest

Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Thanks a lot for this!


pac++

Moderated by  HeelX, Spirit 

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