Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (vicknick, howardR, sleakz), 691 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
pXent_setposition #420299
03/22/13 19:34
03/22/13 19:34
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I tried to make simple drag/drop example with "pXent_setposition", but I've noticed, that while I pick the object up, it's still affected by the gravity, and when I drop it down, it moves down very fast (as if gravity force was increasing while it was picked up). Is that a normal behavior, or one more bug?

Here is the dirty code example:
Code:
#include <acknex.h>
#include <default.c>
#include <ackphysX.h>

ENTITY* movedEnt;

void cubeEvent(){
	// if we have the pointer, function invalid:
	if(movedEnt != NULL){ return; }	
	// we are moving:
	movedEnt = my;
}

void cube(){
	// flags:
	set(my, SHADOW | CAST | LIGHT); 	
	// random color:
	vec_set(my.blue, vector(150 + random(100), random(100), 0));	
	// set random size
	vec_fill(my.scale_x, 0.6 + random(0.4));	
	// activate physics	
	pXent_settype(my, PH_RIGID, PH_BOX);	
	// restitution:
	pXent_setelasticity(my, 30);	
	// set random initial speed	
	pXent_addvelcentral(my, vector(1 - random(2), 1 - random(2), 0));		
	// event type:
	my.emask |= (ENABLE_SHOOT); 	
	// event:
	my.event = cubeEvent;
}

void main(){
	// shadows:
	shadow_stencil = 2;	
	// limit fps:
	fps_max = 60;	
	// open physX engine:
	physX_open();	
	// load empty level:
	level_load("");	
	// place camera:
	vec_set(camera.x, vector(-180, 0, 30));	
	// create ground plate
	ENTITY* ground = ent_create(CUBE_MDL, nullvector, NULL);
	// scale the cube model:
	vec_set(ground.scale_x, vector(20, 20, 1));
	// register it as a static object:
	pXent_settype(ground, PH_STATIC, PH_BOX); 
	// set it's friction:
	pXent_setfriction(ground, 10);	
	// create three cubes:
	ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube);
	ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube);
	ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube);	
	// vector:
	VECTOR temp;	
	// variable:
	var traceTime = 0;	
	// free vector:
	vec_fill(temp.x, 0);	
	// move camera:
	def_move();	
	// loop:
	while(1){
		// define trace position:
		vec_set(temp.x, vector(50, 0, 0));
		vec_rotate(temp.x, camera.pan);
		vec_add(temp.x, camera.x);		
		// draw end position of the trace:
		draw_point3d(temp.x, COLOR_RED, 100, 1);		
		// if we have moving entity:
		if(movedEnt != NULL){			
			// move entity:
			pXent_setposition(movedEnt, temp.x);			
			// if we press mouse left:
			if(mouse_left && traceTime <= 0){				
				// reset pointer:
				movedEnt = NULL;				
				// set timer:
				traceTime = 0.5;				
			}			
		}
		else{			
			// if needed:
			if(traceTime > 0){				
				// count down:
				traceTime -= time_step / 16;				
			}
			else{				
				// define trace mode:
				trace_mode = IGNORE_PASSABLE | IGNORE_PASSENTS | ACTIVATE_SHOOT;				
				// trace:
				c_trace(camera.x, temp.x, trace_mode);				
			}						
		}		
		// wait one frame:
		wait(1);
	}
}

Just come close to the box, so the red square touches it (the end of the trace), to drop the box, press mouse left.
You'll notice, that as soon as you pick the box up, it slowly starts to move downwards (while it's position is changed by pXent_setposition).


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: pXent_setposition [Re: 3run] #420308
03/23/13 00:59
03/23/13 00:59
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
this is just a logical behaviour. you don't change anything except position. So speed and previous acceleration will be stored.

if you want some good manual movement of physics, enable kinematic movement or change the entity type to character, then move it with pXent_setposition or pXent_move.

or as a dirty workaround: if you use pXent_setpositin, also use pXent_setvelocity to reset the speed of the entity.


Visit my site: www.masterq32.de
Re: pXent_setposition [Re: MasterQ32] #420314
03/23/13 09:17
03/23/13 09:17
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
MasterQ32@ thanks for the hints.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: pXent_setposition [Re: 3run] #420360
03/24/13 11:40
03/24/13 11:40
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
So, as a conclusion, I wanted to make a small tip for those, who wants to create drag/drop with physX. Instead of setting kinematic flag or converting entity to PH_CHAR which IS DIRTY (and won't really work properly I think), I would recommend just to reset gravity forces (via pXent_setbodyflag), and then use pXent_setposition to move the entity and pXent_rotate to rotate it with camera. And to make it automatically drop, if carried object hits anything too hard. Maybe later I'll add my small example here.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: pXent_setposition [Re: 3run] #420516
03/28/13 13:22
03/28/13 13:22
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Why you coding this, if we have a function pX_pick()?


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: pXent_setposition [Re: rojart] #420519
03/28/13 14:06
03/28/13 14:06
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
rojart@ I don't really like the pX_pick function... Especially the lag of the objects, from the mouse position. Plus, I need to lock the rotation of the physical object (so it rotates with the camera as well). So, pX_pick offers only very basic solution, which doesn't looks really nice for my needs. (I'm still looking for a way, to create drag and drop system, with better results that I have now).


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

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