playMaker

Author Topic: Need help converting this code to Playmaker (orient object towards mouse)[SOLVED  (Read 3107 times)

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Hi All,

I have a working piece of code that I'm trying to replicate in Playmaker.

Basically it is used to rotate an object towards the position of the mouse, in this case the turret on my battle tank.

Code: [Select]
var traverseSpeed : float = 360; // degrees per second

function Update (){

    var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    var dist : float;

    var plane : Plane = new Plane(Vector3.up, transform.position);

    if(plane.Raycast(ray, dist)){

        var rotation : Quaternion= Quaternion.LookRotation(ray.GetPoint(dist) - transform.position);
        transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, traverseSpeed * Time.deltaTime);
    }
}

I am not sure how to set the "ray" and "plane" variables and do the "if" statement.

How would I turn this into a state machine, or is there are better/simpler way of doing it within Playmaker??

Many thanks :)
« Last Edit: August 24, 2013, 08:00:20 AM by jeanfabre »

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Re: Need help converting this code to Playmaker
« Reply #1 on: August 22, 2013, 02:58:38 AM »
Nobody?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
http://hutonggames.com/playmakerforum/index.php?topic=4025.0

Look at the Angry Ships example.

I cast a ray, hit the ground plane, store the collision point and tell the ship to look at the collision point on one axis.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Hi Lane - thanks very much that's all I needed.

I had thought about using raycasting but this method is much simpler than what was going on in my head..

Thanks again :)

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59
Hi again - just curious why you used a script and not Playmaker to control the transformation of the projectile itself?
« Last Edit: August 25, 2013, 10:04:05 PM by uberwolfe »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Hi again - just curious why you used a script and not Playmaker to control the transformation of the projectile itself?

I had it available for testing things and haven't got around to replacing it yet.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

uberwolfe

  • Junior Playmaker
  • **
  • Posts: 59

I had it available for testing things and haven't got around to replacing it yet.
[/quote]

Ah no worries mate, thanks again for the links. Your FSMs are very insightful :)