Hi.
I was not able to find a decent camera tutorial for Unity in the .net which is more related to the math behind it to do my own scripts. I am not so familiar with 3D Math and have some difficulties with it.
With UDK, which I used before, the Camera setups are quite more easy when using Kismet to do it.
Thanks for any links.
regards
What specifically are you looking for? The 3D math involved with camera setup, from what I recall, is mainly a matrix which tells openGL what to do-- I would not expect someone would ever really need to change this other than orthographic and frustum.
Anyhow, you may get answers searching for projection matrices-- that will likely put you into openGL.
No, I mean stuff like following a character and moving/rotating in a correct manner.
To fully understand something like this:
http://www.unifycommunity.com/wiki/index.php?title=SmoothFollow2
regards
That isn’t really ‘camera math’; that’s just how to make objects move.
What part do you need help with? Is there a particular type of movement you’re wanting to implement?
Hey–
The best way to figure it out is to to it yourself-- that way, you’ll remember, and it will open up a lot of interesting things you can do.
I’ll help you though, with where to start–
You want to go to the scripting page, and line by line, figure out what each function does-- write it out if necessary in your own words.
If you don’t understand programming, then that is what you will need to learn first.
Yes. 2 Types. First one is a spaceship. I got it moving forward and backward, but I do not get behind the math how to rotate it according to the moving direction. In short I would like a freelancer like movement so that the ship follows the mouse into all directions.
using UnityEngine;
using System.Collections;
public class SpaceMover : MonoBehaviour
{
public float speed_step = 10.0f;
public int speed_levels = 5;
public float mouselook_rot_speed = 1.5f;
public float speed_strafe = 10.0f;
private float speed = 0.0f;
private int cur_speed_lvl = 0;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
//if (true)
//{
// float hitdist = 0.0f;
// Plane player_pane = new Plane(Vector3.down, this.transform.position);
// Ray mouse_ptr_ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// //Debug.DrawRay(mouse_ptr_ray.origin, mouse_ptr_ray.direction * 10, Color.red);
// if (player_pane.Raycast(mouse_ptr_ray, out hitdist))
// {
// Vector3 targetPoint = mouse_ptr_ray.GetPoint(hitdist);
// Quaternion targetRotation = Quaternion.LookRotation(targetPoint - this.transform.position);
// transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, mouselook_rot_speed * Time.deltaTime);
// }
//}
// Flying right
float amt = Input.GetAxis("Horizontal");
this.transform.Translate(amt * speed_strafe * Time.deltaTime, 0, 0);
// Speed is determined by the mouse wheel
if ( Input.GetAxis("Mouse ScrollWheel") > 0 )
{
if (cur_speed_lvl < speed_levels)
{
speed -= speed_step;
cur_speed_lvl++;
}
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0 )
{
if (cur_speed_lvl != 0)
{
speed += speed_step;
cur_speed_lvl--;
}
}
// When the speed level is 0, we send the rigidbody to sleep to stop the ship.
// We wake it up again, when the speed level raises.
if ( cur_speed_lvl != 0 )
{
this.rigidbody.WakeUp();
this.rigidbody.AddRelativeForce(Vector3.forward * speed * Time.deltaTime);
}
else
{
this.rigidbody.AddRelativeForce(Vector3.forward * 0);
this.rigidbody.Sleep();
}
}
void OnGUI()
{
GUILayout.Label("Current Speed Level: " + cur_speed_lvl);
}
}
The part which is disabled by comments atm makes the ship controllable by the mouse, I have found this somewhere in this forums, but it is too hmm “fine”. With a few pixels movement, the ship starts spinning already . Dunno if you played Freelancer. There you move the mouse into an direction and the ship follows the mouse.
The other sort of movement:
Diablo style. There is a script for 9.99$, I think I just gonna buy that one or use the 3rd Person Camera of Unity 3. Thats also pretty cool. But the Spacestuff eats my patiente a bit atm.
@iceshaft
Programming in Terms of Syntax and Patterns is not the deal :). I want to understand the math behind to use the according functions properly. I have a somewhat hard time with the math-stuff.
Yep, I understand where you are coming from. I have the same problem in controllong the character the way I want. It is actually a de-facto standard in today’s MMOs, character control is more or less like WoW or the new Aion (which is bettter), but not in the way as the character control in Unity3D’s examples. So I hope that someone can make such a script which should do a great favor to all of us.
That movement control is not only the de-facto standard in today’s MMOs, even Unity3D uses it in its IDE environment. I don’t know why they feel reluctant to release it, which is what everyone is asking for.
Very nice post of camera math. I was tried to move objects with this coding but it shows two errors and not works. I hope you solve this query as soon as possible, I have 't idea to solve this errors.