creazioni siti web rovigo

Unity 3D Game Engine – Android – Swipe – Screen – Move Object

Unity 3D Game Engine – Android – Swipe – Screen – Move Object

Translate a GameObject swiping screen

Hierarchy, create a scene with:

– Main Camera
– Cube (Game Object), attach the script ‘TouchController.js’

TouchController.js


#pragma strict

// Moves object according to finger movement on the screen
	var speed : float = 3.0;
	function Update () {
	    // Se si sta toccando lo schermo e la fase è Moved (il dito sta strisciano)
		if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
		
			// Get movement of the finger since last frame
			var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
			
			// Move object across XY plane
			// Time.deltaTime it move xxx meters per second instead of xxx meters per frame
			transform.Translate (touchDeltaPosition.x * Time.deltaTime * speed, touchDeltaPosition.y * Time.deltaTime * speed, 0);
		}
	}

Hierarchy> Cube> Inspector> TouchController.js setup public var speed:

> speed > movement
< speed < movement

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Android – Swipe – Screen – Move Object

Unity 3D Game Engine – Android – Touch Drag – Moving a 3D Object – JS

Unity 3D Game Engine – Android – Touch Drag – Moving a 3D Object – JS

Inside Hierarchy create:

– Cube (Game Object), position X=0 Y=0.5 Z=0

– Main Camera, move it to see the Cube from top; position X=0 Y=8 Z=0, rotation X=90 Y=0 Z=0, attach the script ‘TouchMove.js’

TouchMove.js


var object : GameObject;

function Update () {
   
	for (var touch : Touch in Input.touches){
		var ray = Camera.main.ScreenPointToRay(touch.position);
		var hit : RaycastHit;
		if (Physics.Raycast (ray, hit, 100)) {
			if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
				var cameraTransform = Camera.main.transform.InverseTransformPoint(0, 0, 0);
				object.transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, cameraTransform.z - 0.5));
			}
		}
	}
}

Hieararchy> Main Camera> Inspector> TouchMove.js> DRAG AND DROP Cube (Game Object) over public var object

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Android – Touch Drag – Moving a 3D Object – JS

Unity 3D Game Engine – Camera – 2D Platform – Smooth Follow

Unity 3D Game Engine – Camera – 2D Platform – Smooth Follow

1. Inside Hierarchy create the structure:

– Player (parent)
— CameraTarget (Empty Object) (child)

– Main Camera

2. Select ‘Main Camera’ and create ‘CameraController.js’

CameraController.js


#pragma strict
 
var cameraTarget : GameObject; // Inspector> Assign the Camera Target NON è il target della camera ma la posizione che vuole raggiungere la camera

var smoothTime : float = 0.1;              // Delay in seconds to follow Player
var cameraFollowX : boolean = true;        // Inspector> if is checked -> The Camera will follow X position of cameraTarget
var cameraFollowY : boolean = true;        // Inspector> if is checked -> The Camera will follow Y position of cameraTarget
var cameraFollowHeight : boolean = false;  // if true the Camera Y Position = cameraHeight
var cameraHeight : float = 2.5;            // cameraHeight
var velocity : Vector2;
private var thisTransform : Transform;    

function Start ()
{
  thisTransform = transform;
}

function Update () 
{

if (cameraFollowX) // if cameraFollowX = true = Inspector is checked
{
  thisTransform.position.x = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x, velocity.x, smoothTime);
}

if (cameraFollowY) // if cameraFollowY = true = Inspector is checked
{
  thisTransform.position.y = Mathf.SmoothDamp (thisTransform.position.y, cameraTarget.transform.position.y, velocity.y, smoothTime);
}

if (!cameraFollowY && cameraFollowHeight)     // if cameraFollowY = false = Inspector is unchecked AND cameraFollowHeight = true = Inspector is checked
{
  camera.transform.position.y = cameraHeight; // The Camera Y position = cameraHeight
}

}

Main Camera> Inspector> LookAt.js> DRAG AND DROP over:
– var Camera Target -> CameraTarget (Empty Object)
– var Player -> Player (Game Object)
– var Smoot Time -> Delay time to reach final position

a. Camera Follow X check | Camera Follow Y check | Camera Follow Height uncheck | Camera Height
-> follow X and Y of cameraTarget

b. Camera Follow X uncheck | Camera Follow Y check | Camera Follow Height uncheck | Camera Height
-> follow Y of cameraTargetr the X value is the current X position in the viewport

c. Camera Follow X check | Camera Follow Y uncheck | Camera Follow Height check | Camera Height
-> follow X of cameraTarget and Y Camera Height value

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Camera – 2D Platform – Smooth Follow

Unity 3D Game Engine – Camera – 3D Platform – Smoot Follow

Unity 3D Game Engine – Camera – 3D Platform – Smoot Follow

1. Inside Hierarchy create the structure:

– Player (parent)
— CameraTarget (Empty Object) (child) -> posizionarlo in alto dietro il Player (con un valore di Z più piccolo)

– Main Camera

2. Select ‘Main Camera’ -> ruotarla leggermente verso il basso per inquadrare il player and create ‘CameraController.js’

CameraController.js


#pragma strict
 
var cameraTarget : GameObject; // Inspector> Assign the Camera Target NON è il target della camera ma la posizione che vuole raggiungere la camera

var smoothTime : float = 0.1;              // Delay in seconds to follow Player
var cameraFollowX : boolean = true;        // Inspector> if is checked -> The Camera will follow X position of cameraTarget
var cameraFollowY : boolean = true;        // Inspector> if is checked -> The Camera will follow Y position of cameraTarget
var cameraFollowZ : boolean = true;        // Inspector> if is checked -> The Camera will follow Z position of cameraTarget
var cameraFollowHeight : boolean = false;  // if true the Camera Y Position = cameraHeight
var cameraHeight : float = 2.5;            // cameraHeight
var velocity : Vector3;
private var thisTransform : Transform;    

function Start ()
{
  thisTransform = transform;
}

function Update () 
{

if (cameraFollowX) // if cameraFollowX = true = Inspector is checked
{
  thisTransform.position.x = Mathf.SmoothDamp (thisTransform.position.x, cameraTarget.transform.position.x, velocity.x, smoothTime);
}

if (cameraFollowY) // if cameraFollowY = true = Inspector is checked
{
  thisTransform.position.y = Mathf.SmoothDamp (thisTransform.position.y, cameraTarget.transform.position.y, velocity.y, smoothTime);
}

if (cameraFollowZ) // if cameraFollowZ = true = Inspector is checked
{
  thisTransform.position.z = Mathf.SmoothDamp (thisTransform.position.z, cameraTarget.transform.position.z, velocity.z, smoothTime);
}

if (!cameraFollowY && cameraFollowHeight)     // if cameraFollowY = false = Inspector is unchecked AND cameraFollowHeight = true = Inspector is checked
{
  camera.transform.position.y = cameraHeight; // The Camera Y position = cameraHeight
}

}

Main Camera> Inspector> LookAt.js> DRAG AND DROP over:
– var Camera Target -> CameraTarget (Empty Object)
– var Smoot Time -> Delay time to reach final position

a. Camera Follow X check | Camera Follow Y check | Camera Follow Height uncheck | Camera Height
-> follow X and Y of CameraTarget

b. Camera Follow X uncheck | Camera Follow Y check | Camera Follow Height uncheck | Camera Height
-> follow Y of CameraTarget the X value is the current X position in the viewport

c. Camera Follow X check | Camera Follow Y uncheck | Camera Follow Height check | Camera Height
-> follow X of CameraTarget and Y Camera Height value

d. Camera Follow Z check
-> follow Z of CameraTarget

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D Game Engine – Camera – 3D Platform – Smoot Follow

Unity 3D – Pathfinding – NavMesh Obstacles

Unity 3D – Pathfinding – NavMesh Obstacles

These items are not baked into the NavMesh, and thus can move around freely while getting in the way.
Questi ostacoli non possono essere attraversati dal’agente, non sono calcolati nel NavMesh e si possono muovere liberamente nella scena.

1. Create a NavMesh
2. Create a ‘targetNavigation’ object
3. Create a NavMeshAgent

4. Create a game object and name it ‘moving obstacle’

Select ‘moving obstacle’ Inspector> ‘Add component’> Navigation> Nav Mesh Obstacle setup

– Radius: radius of the obstacle collider
– Height: height of ther obstacle collider
– Move Threshold (soglia):
– Carve (intagliare):

By |Unity3D, Video Games Development|Commenti disabilitati su Unity 3D – Pathfinding – NavMesh Obstacles