playMaker

Author Topic: set position to terrain hieght?  (Read 3938 times)

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
set position to terrain hieght?
« on: December 31, 2012, 09:46:19 PM »
Hi, some of you may of seen my thread where im making an RTS camera
I'm trying to get the camera to walk on the terrain

I'm currently using a Rigid body currently and it has some obvious drawbacks such as gravity pulling it down a hill etc

I cant seem to find a way in playMaker to make it get the terrain height and smooth follow it as it moves
and what if there is multiple terrains? so maybe some sort of ray cast that goes down, if it hits no terrain, the height doesn't change, if it does, it smooths over it.
Code: [Select]
Terrain.SampleHeight()

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: set position to terrain hieght?
« Reply #1 on: December 31, 2012, 10:17:12 PM »
I've decided to use a Raycast at every 12 frames, then using Raycast hit info, I'm storing its vector in a global variable
then applying it to set position, but its not working so well, for some reason it only applies it once on startup even though I'm casting the ray and getting its info every 12 frames and its not updating
maybe i should put it in its own loop but that wont fix anything at the moment

it appears the get ray cast info is a one shot and cannot repeat for every frame, it would be better if i could update the variable when i cast the ray

Idea's? suggestions?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: set position to terrain hieght?
« Reply #2 on: January 01, 2013, 05:32:52 AM »
I'm currently using a Rigid body currently and it has some obvious drawbacks such as gravity pulling it down a hill etc

gravity can be turned off on the rigidbody component.

I've decided to use a Raycast at every 12 frames, then using Raycast hit info, I'm storing its vector in a global variable
You can without worries use raycast every frame. I have hundreds of objects doing raycast each time, including 5 on my camera. Framerate dropped by maybe 1 frame or so :D It's really negible, especially when you have a look at AI

it appears the get ray cast info is a one shot and cannot repeat for every frame, it would be better if i could update the variable when i cast the ray
That had annoyed me too. I had it lying around with an every frame option. THough alternatively you can always loop entire states with a "nextFrame" action and a transition right back to the same state.
Make the raycast so long that it will always hit the terrain and set the layer mask to the terrain too, so buildings won't bump your camera. Then get the the hit point.

Then create an empty and set the position of that empty every frame to the position of the hit point. Then use smoothFollow with the target set to the empty and the distance set to 0. The height will then be the offset from the terrain.

If this helped you, please say so. It's inpolite to just ignore comments as you did 2 times before. Even if you say that that wasn't what you were asking for :)
Best,
Sven

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: set position to terrain hieght?
« Reply #3 on: January 01, 2013, 01:36:35 PM »
that worked brilliantly, it might be an issue since the raycast is every 12 frames and the ray info is every frame
only concern is if ray info gets info from another ray in the scene, im not sure

but that every frame helped, it should really be default, and if there is issues with it, it should be combined with the raycast action

which btw, the raycast seems to have a buggy start position, always casting from 0,0,0 instead of a specified 0,2,0, which means when the object is at the height, the ray clips and casts down into the water layer below
solution around this is to subtract 1 to the value before I apply it

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: set position to terrain hieght?
« Reply #4 on: January 02, 2013, 06:12:03 AM »
Hi,

 I am not sure about this start position bug. Are you using "fromGameObject" or "fromPosition"

 Can you put a debug line in the action to output the originPos line 107? you will know straight away and likely find that the position may be not what you expect at that point, not the actual action.

bye,

 Jean