unity3d - How can i turn the camera to left and right in unity for a sphere? -



unity3d - How can i turn the camera to left and right in unity for a sphere? -

updated code .. problem cant move ball if hold e button utilize wasd or arrows move ball...and when hold q photographic camera 2 activates , can move ball wasd or arrows...but right axis angle...is ballance game... want not hold e or q alter photographic camera , move ball corecctly angle right axis ball not holding cameras button

using unityengine; using system.collections;

public class controlplayer : monobehaviour {

public float viteza ; // speed ; void start(){ } void update() { if(input.getkey(keycode.q) ) // if hold q photographic camera 2 activates , wasd can move ball { float miscaorizontal = input.getaxis("horizontal"); float miscavertical = input.getaxis("vertical"); vector3 miscare = new vector3(miscavertical,0.0f,(-miscaorizontal)); //also here chande axis photographic camera 2 rigidbody.addforce(miscare * viteza * time.deltatime); } if(input.getkey(keycode.e) ) // here when press e photographic camera 1 activates , alos can move ball if maintain pressing e { float miscaorizontal2 = input.getaxis("horizontal"); float miscavertical2 = input.getaxis("vertical"); vector3 miscare2 = new vector3(miscaorizontal2,0.0f,miscavertical2); // here controls ball photographic camera ..i had alter axis here.. rigidbody.addforce(miscare2 * viteza * time.deltatime); } } }

}

alright, if i'm understanding correctly, want ball move in relation direction photographic camera facing. don't want have hold downwards "q" or "e" while move ball wasd controls.

so there few things i'd mention here, we'll take them 1 @ time. first off, shouldn't have "addforce" within of update call. update called every frame whenever can. it's great input, want phone call in "fixedupdate" instead. provides improve response across many devices. if leave in update, can inaccurate physics results, , missed collisions. there's lot out there on subject, if want know more it, google little while.

as code side, want store reference photographic camera you're using avoid having hold these buttons down.

what mean is:

private photographic camera referencedcamera = null; private void start() { referencedcamera = camera1; } private void update() { if(input.getkey(keycode.q)) referencedcamera = camera2; else if(input.getkey(keycode.e)) refrencedcamera = camera1; }

this way can reference photographic camera beingness used, rather key input. else "state design pattern". below video on "state design pattern." great video tutorial series derek banas set on design patterns, extremely recommend watching them, state pattern potentially solve problem well. should take care of not having hold button downwards in order create move. more or less, buttons allow switch photographic camera beingness used.

https://www.youtube.com/watch?v=mgex35fjbuo

so that solved, want transform input have, , want set in terms of hte photographic camera beingness used. avoid rewriting lot of code on , on again, know these 2 code snippets should pieced one. "referencedcamera" should defined in code i'm write:

private void fixedupdate() { if(referencedcamera != null) { float miscaorizontal = input.getaxis("horizontal"); float miscavertical = input.getaxis("vertical"); vector3 miscare = referencedcamera.transform.transformdirection( new vector3(miscavertical, 0.0f, -miscaorizontal)); rigidbody.addforce(miscare * viteza * time.deltatime); } }

so this, it's same code, there phone call referenced cameras transform take vector 3 input , set in relation photographic camera instead, , add together new relational vector object.

i want recommend looking events rather if checks in update function, beyond scope of question. hope helps , questions, don't hesitate ask.

edit after farther discussion, came across should mentioned. if photographic camera referencing angled, forcefulness applied in angle, maintain in mind. if pointed towards object downward, forwards relative photographic camera apply forcefulness downward, , not exclusively in may consider forwards direction. thought worth mentioning.

unity3d

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -