Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Moving physics Entity #269734
06/04/09 11:06
06/04/09 11:06
Joined: Apr 2009
Posts: 248
Philippines
seecah Offline OP
Member
seecah  Offline OP
Member

Joined: Apr 2009
Posts: 248
Philippines
Hello All,

I've tried to test script19.c from Lite-C tutorials for physics entity.. The boundary of the map works fine on it's original code, but in my game i want to make physics entity that is constantly moving and just control the x & y with key_a and key_d.

I've tried this code below but the problem is the ball will move with a high acceleration. How can I move the physics entity with a controlled acceleration.. Hopefully anybody can give me pseudo codes..

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

///////////////////////////////////////////////////////////////

VECTOR ball_speed;
ENTITY* ball;

function main()
{
	fps_max = 140;
	level_load("roller.wmb"); // load the level
	wait (2); // wait until the level is loaded
 	ball = ent_create ("ball.mdl", vector(-400, 0, 100), NULL); // create the ball
	ph_setgravity (vector(0, 0, -386)); // set the gravity
	phent_settype (ball, PH_RIGID, PH_SPHERE); // set the physics entity type
	phent_setmass (ball, 3, PH_SPHERE); // and its mass
	phent_setfriction (ball, 80); // set the friction
	phent_setdamping (ball, 40, 40); // set the damping
	phent_setelasticity (ball, 5, 20); // set the elasticity
	while (1)
	{
		ball_speed.x += 1;
		ball_speed.y += 1 * (key_cuu - key_cud); // 25 sets the x / y movement speeds
		ball_speed.z = 0; // no need to move on the vertical axis
		phent_addtorqueglobal (ball, ball_speed); // add a torque (an angular force) to the ball
		camera.x = ball.x - 300; // keep the camera 300 quants behind the ball
		camera.y = ball.y; // using the same y with the ball
		camera.z = 1000; // and place it at z = 1000 quants
		camera.tilt = -60; // make it look downwards
		wait (1);
	}
}


thanks



Can't is not an option™
Re: Moving physics Entity [Re: seecah] #269737
06/04/09 11:22
06/04/09 11:22
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans

Code:
 my.skill1 += (key_w-key_s) * 0.02 * (1 + 2 * key_r);
 my.skill2 += (key_a-key_d) * 0.02;


//Then modify it with something like below.
//Key_f is used here as a braking mechanism.
//Acelleration is dependant on key press time :)


while(key_f < 0){wait(1);}
		if(key_f ==1)
		{
			my.skill1 -=0.1*time_step;
			if(my.skill1 <= 0)
			{
				my.skill1 = 0;
			}
			
		}
		while(key_f < 0){wait(1);}
		if(key_f ==1)
		{
			my.skill2 -=0.1*time_step;
			if(my.skill2 <= 0)
			{
				my.skill2 = 0;
			}
			
		}
		while(key_f < 0){wait(1);}
		if(key_f ==1)
		{
			my.skill3 -=0.1*time_step;
			if(my.skill3 <= 0)
			{
				my.skill3 = 0;
			}
			
		}
		if(my.skill1 > 3)
		{
			my.skill1 = 3;
		}
		if(my.skill2 > 3)
		{
			my.skill2 = 3;
		}
		if(my.skill3 > 3)
		{
			my.skill3 = 3;
		}

//OR like this in Vadim647's example

//	if (vec_length(my.skill1)>3) vec_normalize(my.skill1,2);//speed
	//	vec_normalize(my.skill1,vec_length(my.skill1) * 1.35);
	//	my.skill1 += (key_w-key_s) * 0.2;






hope that helps...


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Moving physics Entity [Re: KiwiBoy] #269914
06/05/09 08:30
06/05/09 08:30
Joined: Apr 2009
Posts: 248
Philippines
seecah Offline OP
Member
seecah  Offline OP
Member

Joined: Apr 2009
Posts: 248
Philippines
Thanks for your response Kiwiboy but I can't let it work.. The entity will not move..



Can't is not an option™
Re: Moving physics Entity [Re: seecah] #270093
06/06/09 07:11
06/06/09 07:11
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
AUM 62, Plug and Play, Roller, a stand a lone project.
It is a Physics Ball with jump and key controlled move, provides everything you were after laugh


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage
Re: Moving physics Entity [Re: KiwiBoy] #270101
06/06/09 09:54
06/06/09 09:54
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline
Member
Jaeger  Offline
Member
J

Joined: May 2009
Posts: 258
Chicago
This should also help alot:

http://www.gamingw.net/item.php?id=74598

Re: Moving physics Entity [Re: Jaeger] #270105
06/06/09 10:23
06/06/09 10:23
Joined: Apr 2009
Posts: 298
Southern Oceans
KiwiBoy Offline
Member
KiwiBoy  Offline
Member

Joined: Apr 2009
Posts: 298
Southern Oceans
Awesome tutes there Jaeger, great stuff.
Love the script smile


Use the 'manual' Luke, the manual is your friend. 'Self reminder' smile

My WebPage

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

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