Trace to collision checks

Discussions about Coding and Scripting
Post Reply
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Trace to collision checks

Post by JackGriffin »

I've been aggravating Ferali enough so I'm going to post this here. Can someone tell me if I have this correct?

In my Postal mod I have a check for the dancers like this:

if ( !FastTrace(Best.Location, Winner.Location + 72 * Vector(Rotation) + vect(0,0,-33) * 40 ))

so the breakdown is
-The trace begins at winner location
- The trace ends at 72 units away from the winner's location
- It goes in the direction the player is looking
- Once it reaches it's end it then drops 33 units
- Finally it checks a 40 unit radius around this point

I've googled quite a lot on fast tracing but nowhere is there a good breakdown of extras beyond a->b traces.
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

:thudown: You have that one wrong.

FastTrace(A, B) is a trace performed from B to A (so B->A).

So what you have there is a trace done from
72 units in the direction of Self actor is facing (the actor you're calling this in, not the Winner);
Then drops 33unit * 44 in the Z direction, which is actually a drop of 1452 (=33*44).

What you probably want is:

Code: Select all

if ( !FastTrace(Best.Location + 72 * Vector(Winner.ViewRotation) + vect(0,0,-33), Winner.Location )
This doesn't cover the radial check of 44 units, because you simply cannot do that in a fast trace.
At max, you could do it with VisibleCollidingActors afterwards, but that doesn't give you awareness if there's something that could block it.
Instead, you can try to spawn an actor with a collision of 44 radius (a "collidable" and "blockable" collision) with the property bCollideWhenPlacing=True in that actor.
If it spawns, the area is clear enough, if it fails to spawn, a 44 radius actor doesn't fit there.

EDIT: You can use the platform spawn as that radial spawn check itself, if it succeeds, you can spawn the rest and no extra resources needed.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trace to collision checks

Post by JackGriffin »

Ah...Dammit, I love learning new stuff. Ferali I swear to God if you ever visit the states I'm going to take you crabbing and then have the best driveway beer-n-crab feast you have ever eaten. Why the driveway? Well you cook crabs in seawater and you'll only do that ONCE inside the house (then you know not to ever again). Besides they are a delicious mess and you will get it on your shirt, pants, back of your legs, everywhere. Don't worry, it's like an event here. It's called 'backing crabs' because you literally pull off their backs to get at the good stuff and if you are in your driveway backing and drinking it's allowable that anyone can stop and join in. I've done it a bunch of times on the route (not the drinking part) and you'd surely enjoy it, I promise you.

Anyway..I was dead wrong on this checks thing but now I know. I'll fix my code and try again. And again. And again.

I think I'll go the route of a spawned actor to check collision. That's perfectly doable :) Thanks again for explaining this stuff to me.

EDIT: one last question, and I meant to add this earlier. When I'm spawning my check in the direction the player is viewing am I spawning it flat level or does it check downwards if I am currently looking down at a player?
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

This may disappoint you, but I am not a big fan of crabs rofl :lol2:
They're cool to catch and all, to eat, not so much, but hey, I didn't try every species yet rofl

As for your question, it will make the trace downwards or upwards, in the exact direction of your view.
You can make it flat easily:
instead of:

Code: Select all

vector(Winner.ViewRotation)
you would have:

Code: Select all

Normal(vector(Winner.ViewRotation)*vect(1,1,0))
Basically, by taking out the Z component of the final direction, and normalize it once again to have accurate values when using it.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trace to collision checks

Post by JackGriffin »

OK, one last follow up if you would be so kind <Bioshock reference intended>. Say I have finally found a decent spot to spawn my first dancer. If I then want to get the opposite place is the correct code

Code: Select all

Vector(Rotation * 2)
even if that rotation exceeds the max number of 64k? Or is it more proper to check for max radial limit then start back over at zero?

BTW my checking actor class is called Spawnchecker1. Is the check as easy as

Code: Select all

if (SpawnChecker1 != none
after I attempt to spawn it, or should it carry a counting variable to check?
Last edited by JackGriffin on Fri May 25, 2012 1:16 pm, edited 1 time in total.
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

Nope, if you want the opposite direction you make:

Code: Select all

-vector(Rotation)
Notice that I am negating the vector with the minus (-) signal.

With Rotation * 2 you just obtain 2 times the current rotation:
rot(1,0,0) * 2 = rot(2,0,0)
better yet:
rot(0,0,0) * 2 = rot(0,0,0)

EDIT: Only noticed your edit now: yeah, if the spawn fails, None is returned afaik (since the actor never gets to be fully instantiated at that moment I think).
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trace to collision checks

Post by JackGriffin »

Since this is the end of the game and the heavy lifting of the server is over I'm just going to do a quick radius check for it. I wouldn't do this if it were a running game because I know it's slow but this is acceptable I think.
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

That's actually a good reason to use the spawn, it would be worse to use this method in gameplay.
I mean, making a radius check is:
- slower
- inaccurate
- more complex to code

So why not stick to the fast, accurate and simple? :)
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trace to collision checks

Post by JackGriffin »

Look who you are talking to. I'm very much a

Code: Select all

Velocity = Velocity;
coder and we all know it. :lol:
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

LOL Actually I don't know anyone, from novice coders to pro ones, from RL to UT who would ever commit that coding fallacy, apart from guy who actually wrote that.
I still remember when I was checking that someone's code, and I found that gem :lol2:
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trace to collision checks

Post by JackGriffin »

God knows what you'd find in mine but that's OK with me. It's how I'll learn.

Care to field another question concerning collision? I'm using the stage as a spawn test for room and the stage is 30 units wide. I set it's collision to 40 units to add a little leeway and made collidewithworld true. It does work fine, however if it spawns and is only slightly overlapping an existing actor the engine is gently nudging my table over a bit. This causes the dancer to be off-centered.
Is there a way to prevent this or would it just be better to find the location of the platform and then spawn the dancer onto it directly?
So long, and thanks for all the fish
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Trace to collision checks

Post by Feralidragon »

Yeah, when you have CollideWhenPlacing, if it sinks a bit too much in BSP, it adjusts itself outwards to be out of it (nice feature from the engine), so yeah, it's better if you use the final spawned actor location to then spawn the dancer.
Post Reply