Auto Move character to specific target instead of keyboard controls Unity3d
up vote
0
down vote
favorite
I want to Auto Move my character to following object, instead of keyboards controls, my code works fine on keyboards controls, I am trying to add a target as a gameobject and trying to character to follow it, "dummy" is variable is my public var, where I assign my target as a gameobject", here is my code so far,
protected virtual void UpdateMovement()
{
// var local = Input.GetAxis("Horizontal") * Vector3.right + Input.GetAxis("Vertical") * Vector3.forward;
//works fine at keyboards controls
var local = new Vector3(0,0,0);
local = dummy.transform.position - transform.position; // I tried this but did'nt work
transform.LookAt(dummy.transform);
var movement = new CharacterMovement();
movement.Direction = getMovementDirection(local);
if (WalkWhenZooming && _controller.ZoomInput)
{
movement.Magnitude = 0.5f;
movement.IsSlowedDown = true;
}
else
{
if ((_motor.ActiveWeapon.Gun != null || _motor.ActiveWeapon.HasMelee) && FastMovement)
{
if (Input.GetButton("Run") && !_motor.IsCrouching)
movement.Magnitude = 2.0f;
else
movement.Magnitude = 1.0f;
}
else
{
if (Input.GetButton("Run"))
movement.Magnitude = 1.0f;
else
movement.Magnitude = 0.5f;
}
}
_controller.MovementInput = movement;
}
c# unity3d
add a comment |
up vote
0
down vote
favorite
I want to Auto Move my character to following object, instead of keyboards controls, my code works fine on keyboards controls, I am trying to add a target as a gameobject and trying to character to follow it, "dummy" is variable is my public var, where I assign my target as a gameobject", here is my code so far,
protected virtual void UpdateMovement()
{
// var local = Input.GetAxis("Horizontal") * Vector3.right + Input.GetAxis("Vertical") * Vector3.forward;
//works fine at keyboards controls
var local = new Vector3(0,0,0);
local = dummy.transform.position - transform.position; // I tried this but did'nt work
transform.LookAt(dummy.transform);
var movement = new CharacterMovement();
movement.Direction = getMovementDirection(local);
if (WalkWhenZooming && _controller.ZoomInput)
{
movement.Magnitude = 0.5f;
movement.IsSlowedDown = true;
}
else
{
if ((_motor.ActiveWeapon.Gun != null || _motor.ActiveWeapon.HasMelee) && FastMovement)
{
if (Input.GetButton("Run") && !_motor.IsCrouching)
movement.Magnitude = 2.0f;
else
movement.Magnitude = 1.0f;
}
else
{
if (Input.GetButton("Run"))
movement.Magnitude = 1.0f;
else
movement.Magnitude = 0.5f;
}
}
_controller.MovementInput = movement;
}
c# unity3d
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to Auto Move my character to following object, instead of keyboards controls, my code works fine on keyboards controls, I am trying to add a target as a gameobject and trying to character to follow it, "dummy" is variable is my public var, where I assign my target as a gameobject", here is my code so far,
protected virtual void UpdateMovement()
{
// var local = Input.GetAxis("Horizontal") * Vector3.right + Input.GetAxis("Vertical") * Vector3.forward;
//works fine at keyboards controls
var local = new Vector3(0,0,0);
local = dummy.transform.position - transform.position; // I tried this but did'nt work
transform.LookAt(dummy.transform);
var movement = new CharacterMovement();
movement.Direction = getMovementDirection(local);
if (WalkWhenZooming && _controller.ZoomInput)
{
movement.Magnitude = 0.5f;
movement.IsSlowedDown = true;
}
else
{
if ((_motor.ActiveWeapon.Gun != null || _motor.ActiveWeapon.HasMelee) && FastMovement)
{
if (Input.GetButton("Run") && !_motor.IsCrouching)
movement.Magnitude = 2.0f;
else
movement.Magnitude = 1.0f;
}
else
{
if (Input.GetButton("Run"))
movement.Magnitude = 1.0f;
else
movement.Magnitude = 0.5f;
}
}
_controller.MovementInput = movement;
}
c# unity3d
I want to Auto Move my character to following object, instead of keyboards controls, my code works fine on keyboards controls, I am trying to add a target as a gameobject and trying to character to follow it, "dummy" is variable is my public var, where I assign my target as a gameobject", here is my code so far,
protected virtual void UpdateMovement()
{
// var local = Input.GetAxis("Horizontal") * Vector3.right + Input.GetAxis("Vertical") * Vector3.forward;
//works fine at keyboards controls
var local = new Vector3(0,0,0);
local = dummy.transform.position - transform.position; // I tried this but did'nt work
transform.LookAt(dummy.transform);
var movement = new CharacterMovement();
movement.Direction = getMovementDirection(local);
if (WalkWhenZooming && _controller.ZoomInput)
{
movement.Magnitude = 0.5f;
movement.IsSlowedDown = true;
}
else
{
if ((_motor.ActiveWeapon.Gun != null || _motor.ActiveWeapon.HasMelee) && FastMovement)
{
if (Input.GetButton("Run") && !_motor.IsCrouching)
movement.Magnitude = 2.0f;
else
movement.Magnitude = 1.0f;
}
else
{
if (Input.GetButton("Run"))
movement.Magnitude = 1.0f;
else
movement.Magnitude = 0.5f;
}
}
_controller.MovementInput = movement;
}
c# unity3d
c# unity3d
edited 39 mins ago
asked 45 mins ago
Newbies Studio
160213
160213
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370521%2fauto-move-character-to-specific-target-instead-of-keyboard-controls-unity3d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown