Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by superventure · Dec 20, 2010 at 05:24 PM · crashcharactercontrollerjitter

Riding a second character controlled object

Hey unity people-

I have my hero, and a deer she rides. Both have a character controller. To ride the deer, I've said in script to attach the hero's center to a 'saddle' (an empty game object) I placed inside the deer, when I press the correct button and am in range of the animals side. She is able to get on perfectly in the right position, but when I press my 'run' button (makes the speed go from 7 to 20), the script seems to forget that I put

hero.position = saddle.position;

in the update function... The player is still riding, but she doesn't stay ON the saddle. The deer jerks and shakes forward and acts jittery when walking and more when running. It also makes the game crash after a while.

The thing is, sometimes when I load unity she is able to ride the deer PERFECTLY.

I think it is because their character controllers are colliding so it makes the deer jittery when moving.

The way I set up the script is to turn off the player's controll script and the deer's 'follow the player script', and enable a second script attached to the deer for an all new controlling script for riding.

I can't turn off the player's character controller because I instantly get hundreds of errors. Many things rely on the player current whereabouts- BUT, is there some way to turn off either's controller OR stop the deer from shaking indefinitely?

I have also tried to reposition the deer's controller but it doesn't seem to matter if the controller is no where near the hero or deer when riding- the deer always jitters.

here is the basic script for controlling the animal when riding-

function Update(){

transform.rotation.z = 0;

var rider= GameObject.Find("Player").transform;

var saddle = GameObject.Find("saddle").transform;

var heros = GameObject.Find("Player");

rider.position = saddle.position; rider.rotation = saddle.rotation;

var controller : CharacterController = GetComponent(CharacterController);

var forward = transform.TransformDirection(Vector3.forward);

var curSpeed = speed * Input.GetAxis ("Vertical");

transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

moveDirection.y -= gravity Time.deltaTime; controller.Move(moveDirection Time.deltaTime);

controller.SimpleMove(forward* curSpeed);

if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){ animation.CrossFade("walk");

}else{ animation.CrossFade("idle"); speed = 7;

} if (Input.GetButton ("Jump")) if (controller.isGrounded) { moveDirection.y=jumpSpeed; animation.CrossFade("walk");

}if (Input.GetButton ("run")) { speed = 20;

}if (speed >7){ animation.CrossFade("run");

}if (Input.GetButton("dismount")){ hero.riding = false; heros.GetComponent(playercontrollscript).enabled =true; GetComponent(cowboyscript).enabled = false; GetComponent(followmescript).enabled = true;

} }

Also, I do want the deer's x axis to rotate up or down when riding over the terrain instead of always being straight to the world- how do I allow it to rotate?

AND the deer cannot jump at all when the player is riding it. I also think it is because of the players controller. I tried to turn off gravity for both of them, but it doesn't work.

Any help is very much appreciated!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image superventure · Dec 20, 2010 at 05:54 PM 0
Share

Wow, I just answered the major part of my question- I just put rider.position = saddle.position; rider.rotation = saddle.rotation; after each input command and she now stays in position! Sheesh.. But, the deer still doesn't rotate up or down according to the terrain and still can't jump upwards more than 2 inches off the ground. Can anyone help?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mickydtron · Dec 20, 2010 at 06:27 PM

There are a lot of questions in there, and I can't answer all of them, but I think it would help you if instead of setting the players transform equal to that of the saddle each update, you just set saddle to be the parent of the players transform. That is,

var playertransform = GameObject.FindWithTag("Player").transform;
var saddle = GameObject.Find("Saddle").transform;
playertransform.parent = saddle;

This should execute during the mounting event. Then, during dismount, we set the players transform to have no parent:

playertransform.parent = null;

As far as the x rotation of the deer goes, what you want to look for is the normal vector of the ground you are standing on, which you want to be your "up" vector. As for how to execute that in code, I would start with looking at the code in the CharacterMotor.js script related to groundNormal. It uses groundNormal = hit.normal; to get the normal, and the AdjustGroundVelocityToNormal function to make sure we run across the ground.

private function AdjustGroundVelocityToNormal (hVelocity : Vector3, groundNormal : Vector3) : Vector3 {
    var sideways : Vector3 = Vector3.Cross(Vector3.up, hVelocity);
    return Vector3.Cross(sideways, groundNormal).normalized * hVelocity.magnitude;
}

You could run the same calculations as that function and then set the rotation equal to looking along the velocity vector.

var forward = AdjustGroundVelocityToNormal (hVelocity, groundNormal);
transform.rotation = Quaternion.SetLookRotation(forward,groundNormal);

For the deer jumping, I got nothing, unless you want to completely restructure your approach so that you set the deer to be child of the rider, and change the riders controller attributes accordingly (speed, height from ground, etc). We wouldn't be controlling the deer directly anymore, but the player-deer combined object thing. This would make a lot of what I wrote previously fairly irrelevant, too.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by suyujin · Dec 31, 2011 at 11:01 PM

You can use most of what Mickydtron said and I think that will all work, then to get jumping to work, I would guess it's not working because the deer collides with the player controller. You can use Physics.IgnoreCollision(); in your deer script. Would be something to the extent of Physics.IgnoreCollision(player.collider, collider); Make sure that's in your deers controller for when the player mounts it. Hope that helps!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Jan 01, 2012 at 04:22 AM 0
Share

I hope they've already gotten it to work by now... this was asked over a year ago.

avatar image suyujin · Jan 01, 2012 at 10:08 PM 0
Share

Oh crap. Haha. I always forget to check the dates on these!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

jittering when moving 3 Answers

Character Controlling grinding along any non-flat Terrain 1 Answer

Charactercontroller jittering while jumping into wall 0 Answers

Unity crashes on certain collisions 1 Answer

Character Controller Jitter On Platform With Animation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges