|
Hey all, This is for a teleport feature. I am about to write a function that returns if a position is inside of a collider.That way I can negate the teleport, so the player doesn't go inside of objects. Does unity have some magic way of doing this? I have an idea of how I can do it, but I wanted to ask here first in case there was an built in way / simple way one of you guys knew of. Thanks
(comments are locked)
|
|
Guys I found a good simple way of doing this. Thanks for the responses. Here is a hunk of code I used a sweeptest on my rigidbody, I used distance and direction of my teleport location and used it as the ray to send out. I tested the what my RaycastHit got assigned to like this.
Check out unity SweepTest() and Collider.bounds for specific syntax and what not Hey, great to report your solution, but you should really mark your question as answered (using your answer). Cheers
Jan 02 '11 at 10:56 PM
Socapex
I tried already. Says I have to wait 47 hours for some reason )=
Jan 02 '11 at 11:18 PM
s4vi0r
Oh yes thats true :) Srry
Jan 03 '11 at 12:02 AM
Socapex
I believe `bounds` is always just a cube, so it might not be exactly what it seems (the precise collider mesh boundary). Try this instead: http://answers.unity3d.com/questions/163864/test-if-point-is-in-collider.html
Nov 27 '12 at 05:42 PM
Cawas
(comments are locked)
|
|
You can use triggers to check if objects are colliding. In the collider inspector of your object, turn on 'Is Trigger'. Then you can create a script on your object that sends out values using the OnTriggerEnter(){}, OnTriggerStay(){} and OnTriggerExit(){} functions. Edit: You could make your teleport OnTriggerEnter(){} function modify the location of the character easily. You can access your players location from that function and change it. Make sure one of the colliding objects is a rigidBody, since it wont trigger with an other static collider. Checl the Collision action matrix here for more information on triggers and what will trigger them. Also, the 3d platform tutorial covers teleports IRC. Their solution might be more complete than mine, can't remember how they did it though.
(comments are locked)
|

What do you mean by negate the teleport?
On collision, make the player's transform (Position) where you want it to be... If you want a random position, you can make it randomly select it from a couple of positions (Use empty gameobjects perhaps to get it, then you just move the player to that spot...).