Hi,
I’m sure this is elementary for the wizards reading this, but I’ve searched and searched and I just can’t implement it with my set up. I have a 2D game, with an isometric camera. I have a cube with only 1 side textured facing the camera. The cube is hit (its a golf ball) and flies off in a random direction depending on the wind strength - but it always faces up, even if the ball is curving off to the west, so I wanted it to check the direction it was flying in and face that and update each frame during flight.
This is my code so far:
#pragma strict
internal var ballHeight : float;
var power : float = 100.0;
var height : float = 80.0;
var windx : float;
var windy : float;
var windSpeed : float;
function Update () {
if (Input.GetButtonUp("Fire1")){
hitball();
}
rigidbody.AddForce(Vector3.right * windSpeed, ForceMode.Acceleration);
//change size of sprite on height
ballHeight = transform.position.z;
transform.localScale = Vector3(ballHeight / 3 + 2,ballHeight / 3 + 2,ballHeight / 3 + 2);
//change rotation to match direction (add if statement to be above height of 10 else look straight)
transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
}
function hitball() {
windSpeed = Random.Range(-15.0, 15.0);
rigidbody.AddForce(Vector3(windx,power,height + windy));
}
It almost works, but it spins the cube so that the isometric camera can no longer see it. This is a top down golf game, but I have set the gravity on Z so that the golf hole is actually ‘stood’ up in the scene.
I must have tried about 10 different bits of code ‘tweaked’ alas getting nowhere, and I’m sure this is such a SIMPLE thing - that I’m just to new to understand.
Any help appreciated.
Korpers.