0 registered members (),
744
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to confirm collision with level blocks?
#443852
07/26/14 11:50
07/26/14 11:50
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
I'm working on a wall-running feature in a 3D game. When the player presses the button, the monster dashes forward. If he bumps into a wall, he should start his wall-run, otherwise he should continue in his normal state. I tried to use hit.nx so I could get the normal to the hit surface and rotate the monster's tilt to be parallel to that normal. The problem is hit.nx seems to only return a value if an entity was hit, but not if a level block was hit. That's exactly the opposite of what I'm trying to do. A better way to go about this please?
if(my.state == 12) //Obilicleon Wall-Running
{
while(key_enter || joy_3)
wait(1);
while(my.state == 12)
{
while((dash<100) && WallRunning == 0)
{
dash += 10 * time_step;
my.animation = 75; //75% animation frame is run3
ent_animate(me, "run", my.animation, 0);
c_move(me, vector(dash*time_step, 0, 0), vector(0, 0, -distancedown), USE_POLYGON |IGNORE_PASSABLE);
if((dash > 100) && (hit.nx != 0))
{
dash = 0; my.animation = 0; WallRunning = 1;
my.roll += 90; //temporary. Will replace with code to orient model to normal of hit surface
CameraChaseWallRun(me);
}
else if((dash>100) && hit.nx == 0)
{my.state = 3;} //state that waits for button release before reverting to state 1
wait(1);
}
....rest of wall-run state code
}
}
|
|
|
Re: How to confirm collision with level blocks?
[Re: DLively]
#443919
07/27/14 22:16
07/27/14 22:16
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
Right now, I'm using this code snippet but it returns a value whether or not I hit a wall
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);
While we're at it, after using a c_trace, I want to store the pointer to hit. I can't use ENTITY* or something similar. Please what kind of variable can I store it in?
|
|
|
Re: How to confirm collision with level blocks?
[Re: tolu619]
#443922
07/27/14 22:47
07/27/14 22:47
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
I think EVENT_BLOCK is activated just by my entity's feet being in contact with the regular floor. I just tried this and I get a "met a wall" message every frame.
function ObilicleonWallRun()
{
if(event_type == EVENT_BLOCK)
{
WallRunning = 1;
printf("Met a wall");
}
}
THEN WITHIN THE MONSTER'S ACTION CODE...
if(my.state == 12) //Obilicleon Wall-Running
{
while(key_enter || joy_3)
wait(1);
WallRunning = 0; dash = 0; my.z += 20;
my.emask |= ENABLE_BLOCK;
my.event = ObilicleonWallRun;
while(my.state == 12)
{
while((dash<100) && WallRunning == 0)
{
my.red += 10; my.ambient = 100; my.lightrange = 100;
dash += 12 * time_step;
my.animation = 75; //75% animation frame is run3
ent_animate(me, "run", my.animation, 0);
c_move(me, vector(dash*time_step, 0, 0), vector(0, 0, -distancedown), USE_POLYGON |IGNORE_PASSABLE | IGNORE_SPRITES);
if((dash>100) && WallRunning == 0)
{
my.red = 0; my.ambient = 0; my.lightrange = 0; my.state = 3;
} //leave wall-running state because he didn't meet a wall
....rest of wall-run code here assuming he doesn't leave the wall-running state
}
|
|
|
Re: How to confirm collision with level blocks?
[Re: tolu619]
#443926
07/28/14 02:59
07/28/14 02:59
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
Serious User
|
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);
The reason this will not work is because you are tracing 100 quants on the x axis, rather than in front of the entity itself. In order to trace in front of the entity, you will need to use some trig first, and store it inside a VECTOR, and trace from my.x, to the VECTOR you've created. As old as this AUM is, it covers basic trig to achieve what you will need in order to get the correct direction for your trace. Also, you can check to see if your trace has hit something, like this:
result = c_trace(my.x, trace_distance.x, FLAGS);
if(result > 0){beep();}//Hit something
> 0 Distance to the hit polygon of the target or of the next obstacle in the way. <= 0 No polygon was hit.
|
|
|
Re: How to confirm collision with level blocks?
[Re: DLively]
#443979
07/28/14 15:05
07/28/14 15:05
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);
The reason this will not work is because you are tracing 100 quants on the x axis, rather than in front of the entity itself. In order to trace in front of the entity, you will need to use some trig first, and store it inside a VECTOR, and trace from my.x, to the VECTOR you've created. As old as this AUM is, it covers basic trig to achieve what you will need in order to get the correct direction for your trace. Also, you can check to see if your trace has hit something, like this:
result = c_trace(my.x, trace_distance.x, FLAGS);
if(result > 0){beep();}//Hit something
> 0 Distance to the hit polygon of the target or of the next obstacle in the way. <= 0 No polygon was hit.
The code in that AUM looks like it would detect even entities. I only want to detect level blocks
|
|
|
Re: How to confirm collision with level blocks?
[Re: Superku]
#444007
07/28/14 18:04
07/28/14 18:04
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
Serious User
|
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
The code in that AUM looks like it would detect even entities. I only want to detect level blocks Its the Trig I was getting you to look into, and see how to set a vector in front of the entity, using Sin and Cos.
|
|
|
Re: How to confirm collision with level blocks?
[Re: DLively]
#444014
07/28/14 22:51
07/28/14 22:51
|
Joined: Jun 2014
Posts: 97 Lagos, Nigeria
tolu619
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2014
Posts: 97
Lagos, Nigeria
|
The code in that AUM looks like it would detect even entities. I only want to detect level blocks Its the Trig I was getting you to look into, and see how to set a vector in front of the entity, using Sin and Cos. Oh, thanks. That's actually quite useful
|
|
|
|