Author Topic: Creating new actions...  (Read 2052 times)


  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Creating new actions...
« on: June 07, 2011, 06:01:48 AM »
Can any script be used so long as it's noted properly? even if it's a javascript?

reason i ask is i have a camera control script that i like and it's pretty good for what i need it for... but for reasons of efficiency (translation: lazyness ;) ) i would like to see about adding it to the library of actions available so that it's a simple matter of adding it... this would also allow me to create an easier method to control cutscenes with the camera... toggling off the script and getting it to move to a specific location when a certain event is met.

for note, the script i use is here and as follows. it was created by cobbling together script snippets from the unity forum and unity answers website so i can't lay claim to it (though i forget who authored the bits used.)

Code: [Select]
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour
    public GameObject player;
//The offset of the camera to centrate the player in the X axis
public float offsetX = -5;
//The offset of the camera to centrate the player in the Z axis
public float offsetY = 0;

public float offsetZ = 0;
//The maximum distance permited to the camera to be far from the player, its used to     make a smooth movement
    public float maximumDistance = 2;
//The velocity of your player, used to determine que speed of the camera
public float playerVelocity = 10;

    private float movementX;
private float movementZ;
private float movementY;

// Update is called once per frame
    void Update ()
        movementX = ((player.transform.position.x + offsetX - this.transform.position.x))/maximumDistance;
        movementY = ((player.transform.position.y + offsetY - this.transform.position.y))/maximumDistance;
        movementZ = ((player.transform.position.z + offsetZ - this.transform.position.z))/maximumDistance;
        this.transform.position += new Vector3((movementX * playerVelocity * Time.deltaTime), (movementY * playerVelocity * Time.deltaTime), (movementZ * playerVelocity * Time.deltaTime));

as you can tell, it exposes the offsets needed to allow for proper camera placement. it doesn't (yet) take into account the rotation of the camera and when i come across a need for such control, i'll probably try and work that in but for now, it does what i need it to.

so... how can i turn this into an action? (yes, i am a newb and i am not very good at coding. i can barely scratch by but that's kinda the reason i purchased playmaker, to avoid the headaches of having to learn code instead of actually just getting to making my games.)

yeah, i realize now that this is a C# script... guess that goes to show how noobish i am with coding when i can't determine at a glance wether a script is java or C# :lol:
« Last Edit: June 07, 2011, 06:04:08 AM by Red »


  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 50
    • View Profile
Re: Creating new actions...
« Reply #1 on: June 07, 2011, 08:00:55 PM »
Red,  Check out

Outlines how to start making actions.