|
Complex Math
#296274
10/30/09 17:29
10/30/09 17:29
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
I believe this should be possible. I want to randomly drop an object in a square area 416 x 416. Which means it is divided into 13 square grids 32 x 32. I want to drop the object squarely in the center of any one of these grids. This is the code that drops the object randomly:
myObject = ent_create("physics_test.mdl",vector(random(384)-192,random(384)-192,340),NULL);
phent_settype(myObject,PH_RIGID,PH_SPHERE);
phent_setmass(myObject,360,PH_SPHERE);
phent_setfriction(myObject,100);
phent_setelasticity(myObject,15,100);
//phent_setdamping(myObject,30,5);
ph_setgravity(vector(0,0,-500));
I know this requires some maths. I tried using sqrt(), but I am not getting it right. Can someone help me out here please?
|
|
|
Re: Complex Math
[Re: JGGamer]
#296484
11/01/09 03:54
11/01/09 03:54
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this untested code, it should do what your after...
temp.x = (integer((random(384)-192)/32)*32)+16;
temp.y = (integer((random(384)-192)/32)*32)+16;
temp.z = 340;
myObject = ent_create("physics_test.mdl",temp,NULL);
(if its not too late of course)
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Complex Math
[Re: EvilSOB]
#296520
11/01/09 15:02
11/01/09 15:02
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
It's never too late to change a long code to a short. I'll try it and get back to you. Thanks. Off this topic though, I wonder if you can help me with this problem I am having.
//Function for finding polygons
function checkSolid(ENTITY* myObject)
{
set(my,PASSABLE);
pos_result2 = c_trace(vector(myObject.x,myObject.y,myObject.z),
vector(myObject.x,myObject.y,myObject.z-600), USE_POLYGON);
if (pos_result2 > 0)
{
// Set the entity's physical properties.
/* Registers / unregisters an entity with the physics system.*/
phent_settype(myObject,PH_RIGID,PH_BOX);
/* (In Kilograms) The smallest mass you can specify is 0.001.
The conversion factor from pounds (on Earth) to kilograms is 1 lb. =
0.45 kg.*/
phent_setmass(myObject,5,PH_BOX);
/* (For collisions) friction is what makes objects stick to each other,
when moved sideways. Whenever possible you should set friction to 0,
as this speeds up the calcuations and prevents instability.*/
phent_setfriction(myObject,0);
/* Bounce */
phent_setelasticity(myObject,15,100);
/* Apply force and torque. */
phent_setdamping(myObject,0,0);
/* Gravity */
ph_setgravity(vector(0,0,-200));
}
else
{
//If it misses
ent_remove(myObject);
replot1 = 1; //recreate it
}
}
I created an object which uses this function. It works fine. I tested it over and over to make sure the object finds a solid surface below it, and it does every time. My problem is, I created another object which I want to do the same. However, although I used another function, with the same code (entity name changed), the other object falls and misses the solid surface repeatedly. Why does it fall if it uses c_trace to detect if there is a solid surface beneath it, and finds none? It's not supposed to fall until it detects a solid surface. I don't understand it. I tried many ways to correct this and I am getting nowhere. Would you be able to explain why this is not working?
|
|
|
Re: Complex Math
[Re: JGGamer]
#296798
11/03/09 01:42
11/03/09 01:42
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
I couldn't get your code to work, but don't bother with that, the one I am using is working fine. Thanks
lite-c is simple in some areas, but quite complicated in others. Maybe because I don't understand it. It's quite similar to python, which I had been using previously, but in areas that I thought should be quite simple, I am getting crashes and headaches. For example, with python, once I declare a global variable I can use it anywhere, and at anytime, without breaking a rule. With lite_c, these functions are killing me off. I can't use variables etc. as freely as I like without getting a crash.
I like lite-c, as I said before, but some areas are truely frustrating me. Just thought I'd share my thoughts with someone. That sometimes help I understand.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|