problem understanding c_trace and vec_dist

Posted By: ncc1701d

problem understanding c_trace and vec_dist - 03/01/10 09:27

newby here
can someone take a look at this and tell me what I am doing wrong? I am just trying to use c_trace and vec_dist for the first time. I am trying to display the distance between 2 balls using those 2 types of code tools. thanks

///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>

////////////////////////////////////////////
var distance = 0;//ok
ENTITY* ball1;
ENTITY* ball2;


PANEL* first_pan =
{
digits (30, 30, 2, *, 1, distance);
flags = VISIBLE;
}


function earth()
{
ball1 = my;
my.ambient = 100;
c_trace(my.z,ball2.z,USE_BOX);
distance = vec_dist(my.z,ball2.z);

}


function testball()
{
ball2 = my;
my.ambient = 0;
}


function main()
{
level_load("small.hmp");
ball1 = ent_create("earth.mdl", vector(0, 0, 30), earth);
ball2 = ent_create("testball.mdl", vector(0, 0, 65), testball);
}
Posted By: Helghast

Re: problem understanding c_trace and vec_dist - 03/01/10 09:31

you dont need c_trace.
only vec_dist will be good enough.

vec_dist returns the distance between 2 vectors.
c_trace creates a line between 2 points, and checks for collision along the way.
if it hit's anything, it will return the distance from the position it traces to the point it hits something.

hope I made some sence there.

regards,

EDIT: after looking more closely at your code, there are several issues.
Dont load a .hmp file, create a wmb with WED that you load.
also, here is the script fixes I made in your code.
now it should work:

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

////////////////////////////////////////////
var distance = 0;//ok
ENTITY* ball1;
ENTITY* ball2;

PANEL* first_pan =
{
	digits (30, 30, 2, *, 1, distance);
	flags = VISIBLE;
}

function main()
{
	level_load("small.wmb");
	wait(5);
	
	ball1 = ent_create("earth.mdl", vector(0, 0, 30), NULL);
	ball2 = ent_create("testball.mdl", vector(0, 0, 65), NULL);
	
	distance = vec_dist(ball1.x, ball2.x);
}



If you want to constantly update the distance, put the vec_dist calculation in a loop in your main function.
Posted By: ncc1701d

Re: problem understanding c_trace and vec_dist - 03/02/10 00:20

Thank you. Thats a huge help. I assumed I had to use c-trace but I was way over complicating this.
But now do I have to use c-trace somehow to display the distance from the ball to the the landcape on the floor of the level? I might think not based on what your telling me but then someone else mentioned i need that so I wanted your expert opinion on if I need c-trace to show distance from landscape ground and the ball. Thanks
Posted By: Superku

Re: problem understanding c_trace and vec_dist - 03/02/10 01:03

AFAIK it's okay to load a hmp (level_load("small.hmp")), not a wmb (this was impossible in prior gamestudio versions, though).

Quote:
I am trying to display the distance between 2 balls using those 2 types of code tools.

Quote:
But now do I have to use c-trace somehow to display the distance from the ball to the the landcape on the floor of the level?


Are you dealing with two different problems or is your issue just the first one? In the latter case Helghast's code is fine.
Posted By: ncc1701d

Re: problem understanding c_trace and vec_dist - 03/02/10 03:30

It would be the same sitution only displaying distance from 1 ball to the ground
© 2024 lite-C Forums