playMaker

Author Topic: Keep unit inside area [SOLVED]  (Read 136 times)

marvoc

  • Playmaker Newbie
  • *
  • Posts: 30
    • View Profile
Keep unit inside area [SOLVED]
« on: September 18, 2019, 05:02:15 AM »
Hello again:)
Im fighting with an issue, how to keep player unit inside area. But in this case this inner space has cone like shape. And unit can be near to the top or bottom. Because shape is 4side cone, dimensions are different in term of height too. Smaller area on top larger at bottom. Here is picture:

https://drive.google.com/file/d/1X2OGJxhjaC3ofaxM2dZ3w3TIwy-MMfka/view?usp=drivesdk

You can see it on middle picture.
In pic.2 you can see that perpsective of camera creates non linear view. And within this area I have to keep the player.

My first idea was to do this with angeled boxes with enter trigger. So when you go right and hit Ill clamp X axis on joystick (getting Horizontal and Vertical axis). But when I moved up/down player unit made a ugly zigzag effect as it went by side on angeled wall (still same height level).
So doesnt work.

My second idea was only make walls physical and collision with player should stop it. But then I need Riggidbody as Kinematic and then starts to rotate and jump away. So doesnt work for me, at least what I know:)

Third idea was do a 4 raycast in every direction and clamp its destination. So when destionation from wall lower then 1 I have to clamp that direction.
If I compare values then I should go to another node, there should be again getting joystick axis and clamp value of that direction and again raycast which stores destination from a wall + compare if value that destenation is bigger then 1 go back to previews node (base) this should be for each direction.
And lets say if this work what happen if you are in the corner.

Is it some easiest way how to do it? :)

Thanks

Martin
« Last Edit: September 20, 2019, 01:30:45 PM by marvoc »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4545
    • View Profile
    • jinxtergames
Re: Keep unit inside area
« Reply #1 on: September 18, 2019, 07:36:40 AM »
Hi.
I can't see the picture as i would need permssion 1st.
It better to use Imgur or something similar to upload and show pictures on forums :)

marvoc

  • Playmaker Newbie
  • *
  • Posts: 30
    • View Profile
Re: Keep unit inside area
« Reply #2 on: September 18, 2019, 07:56:00 AM »
Ahh sorry, now should work. Yes for nextime Ill try to use something else :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4545
    • View Profile
    • jinxtergames
Re: Keep unit inside area
« Reply #3 on: September 18, 2019, 08:56:17 AM »
Hi.
Set some colliders as a child on the camera
and set collider layers so that it only collides with player would be my 1st thing to try.

But you mentioned that you need rigidbody.
Are you not using Rigidbody on the player?

another possibility to use is having object on each side of the player and use the action "Game Object Is Visible" for each side, disabling movement into that direction.
But it would have issues if player can go closer to the camera.

marvoc

  • Playmaker Newbie
  • *
  • Posts: 30
    • View Profile
Re: Keep unit inside area
« Reply #4 on: September 18, 2019, 11:19:10 PM »
Hi,
 as you mentioned, now I have colliders as camera children with collision layer. But in this case I should have tag for each plane different. Like top/bottom/right and left to recognize which direction should be stopped.

Yes my player unit has Rigidbody, but I tried with "no kinematic" and colliders arent triggers. When I hitted wall the player start to rotate (maybe because of this, then moves to wierd directions).

I though that to setup player with rigidbody would be easy, or I miss something important :)

Btw. I read about Rigidbody, is better to use for movement rigidbody.velocity, but Im using translate only.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4545
    • View Profile
    • jinxtergames
Re: Keep unit inside area
« Reply #5 on: September 19, 2019, 06:41:41 AM »
Hi
Ah yes translate is not good to use as it kind of ignores collision, thats probably why you get the issue that it moves into wier directions

marvoc

  • Playmaker Newbie
  • *
  • Posts: 30
    • View Profile
Re: Keep unit inside area
« Reply #6 on: September 20, 2019, 01:29:48 PM »
Yes so it was because I used Translate instead of Set Velocity which is for physic objects.
Now its working, thanks :)