playMaker

Author Topic: Physics and moving platform [SOLVED]  (Read 18432 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #30 on: August 04, 2014, 03:59:26 AM »
Hi,
 
Ok, have you tried this:

http://hutonggames.com/playmakerforum/index.php?topic=2327.0

And also, I can't find the original trhead on this, but I made an elevator scene using iTween and character controller and all is working very well. I have attached the scene again on that  post. It's basically showing how to create lifts, but instead of moving up and down simply move sideways, the principles is identical.


Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #31 on: August 04, 2014, 07:48:10 AM »
Hi Jean,

Ive taken a look and have applied to game but it still dont behave correctly as im using physics and not a character controller. Ive basically adapted your example and tested in a new scene.

to save you reading back on this post, basically my character attaches to the moving platform using Set Parent. All works fine. When using a platform with iTween it causes the player to slowly slide of the platform. The only way ive got it to work is with FixedUpdate without iTween. It seems from mine and grahams conversation is that iTween doesnt seem to work with FixedUpdate/Realtime feature?

ive also tried using 'is kinematic' set on the platform but behaves the same. im at a loss now :( i like the flexibility of iTween but wont behave correctly.

sorry if anything ive said above is not quite correct.

thanks

Nick

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #32 on: August 05, 2014, 04:04:49 AM »
Hi,

 never attach transforms when using Physics. That's never going to work out well. ONLY use either the natural physics engine behavior to have objects colliding with one another or use joints ( fixed joints would do here).

 Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #33 on: August 05, 2014, 05:16:02 AM »
Hi, ok i sort of understand what you mean. ill have to do a bit of research.

The only reason i need the platform as the parent is that when the player jumps up and down (when on the platform) they move with the platform horizontally too.

this is the script im currently using for my moving platform (works ok), can this be achieved in playmaker alone? behavior is like itween ping pong.

Code: [Select]
using UnityEngine;
using System.Collections;

public class MovingPlatform : MonoBehaviour {

public Transform DestinationSpot;
public Transform OriginSpot;
public float Speed;
public bool Switch = false;

void FixedUpdate()
{
// For these 2 if statements, it's checking the position of the platform.
// If it's at the destination spot, it sets Switch to true.
if(transform.position == DestinationSpot.position)
{
Switch = true;
}
if(transform.position == OriginSpot.position)
{
Switch = false;
}

// If Switch becomes true, it tells the platform to move to its Origin.
if(Switch)
{
transform.position = Vector3.MoveTowards(transform.position, OriginSpot.position, Speed);
}
else
{
// If Switch is false, it tells the platform to move to the destination.
transform.position = Vector3.MoveTowards(transform.position, DestinationSpot.position, Speed);
}
}
}
« Last Edit: August 05, 2014, 05:19:45 AM by coxy17 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #34 on: August 06, 2014, 03:37:56 AM »
Hi,

 Yes, this is feasible in PlayMaker, but if using some custom actions to provide access to actions that lets you operate in the FixedUpdate call.

 typically, you can find them all on the ecosystem, search for "advanced".

Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #35 on: August 07, 2014, 12:48:22 PM »
Hi Jean,

Ive taken a look through the Ecosystem and cant find any script which i could use for this? looks like im out of options, not technically minded enough to work this out by writing one to incorporate into playmaker, not to worry.

thanks anyway

nick

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #36 on: August 08, 2014, 04:45:38 AM »
Hi,

 Ok, don't worry, it's all there. Get back to me next week, I'll make a working sample in playmaker doing what this script does.

 Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #37 on: August 12, 2014, 05:57:37 AM »
thanks, is it complicated to make? just reminding you as its next week now :)

greatly appreciated

Nick

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #38 on: August 18, 2014, 01:15:50 AM »
Hi,

 ok, I worked a new ecosystem sample for this, where it shows the good and bad way to do this ( with the right custom actions) and how ti affects the physics simulation.

You can download it here

Bye,

 Jean

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #39 on: August 19, 2014, 12:44:18 PM »
Hi Jean,

the samples are great. however, i noticed that the cubes in the demo scene have drag on them when the platform returns. Im after the behaviour where the player moves with the block with precision and no shaking/drag.

Ive used your demo and have tried my player as a child of the platform and also i have tried this the way you have in your demo (not a child object) but my character falls off very quickly?

Ive tried tweaking with the player settings but still no joy.

Nick


coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #40 on: September 05, 2014, 07:56:50 AM »
no luck. just used a script instead.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14593
  • Official Playmaker Support
    • View Profile
Re: Physics and moving platform
« Reply #41 on: September 09, 2014, 05:17:18 AM »
Hi,

 if you use the physics engine, then this drag and player behavior is to be expected (especiall if it has a weight), indeed you'll need to switch into a non physics behavior if you want a completly still player on a moving platform. It can be done with PlayMaker, but script will be fine of course.

 Bye,

 Jean

sebaslive

  • Hero Member
  • *****
  • Posts: 558
    • View Profile
    • Frame Tale Studios
Re: Physics and moving platform
« Reply #42 on: September 11, 2014, 08:52:44 PM »
Hey Coxy, what script did you end up using??
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Re: Physics and moving platform
« Reply #43 on: October 29, 2014, 04:09:50 PM »
hey sorry for the late reply, here is the code i used

Code: [Select]
using UnityEngine;
using System.Collections;

public class MovingPlatform : MonoBehaviour {

public Transform DestinationSpot;
public Transform OriginSpot;
public float Speed;
public bool Switch = false;
private float pauseTime;
public float delayBeforeMoving;
private bool arrivedAtOurDestination = false;

void FixedUpdate()
{
// For these 2 if statements, it's checking the position of the platform.
// If it's at the destination spot, it sets Switch to true.
if((transform.position == DestinationSpot.position) && !arrivedAtOurDestination)
{
Switch = true;
pauseTime = Time.time + delayBeforeMoving;
arrivedAtOurDestination = true;
}
if((transform.position == OriginSpot.position) && !arrivedAtOurDestination)
{
Switch = false;
pauseTime = Time.time + delayBeforeMoving;
arrivedAtOurDestination = true;
}

// If Switch becomes true, it tells the platform to move to its Origin.
if(Switch && (Time.time > pauseTime))
{
transform.position = Vector3.MoveTowards(transform.position, OriginSpot.position, Speed);
arrivedAtOurDestination = false;
}
else if (Time.time > pauseTime)
{
// If Switch is false, it tells the platform to move to the destination.
transform.position = Vector3.MoveTowards(transform.position, DestinationSpot.position, Speed);
arrivedAtOurDestination = false;
}
}
}